while replacing the input string spaces with underscore and then checking it it does not replaces

Question:

    game=input("enter student name to update report card: ")
    nn=game.replace("  ", "_")
    mycursor.execute("show tables")
    klm = mycursor.fetchall()
    if (nn,) in klm:
        b=int(input("enter sno: "))
        mycursor.execute("select * from {} where sno='{}'".format(nn,b))
        xer=mycursor.fetchall()
            
    else:
        print("no student record found")

this does not execute the if statement it directly goes to the else even though i have table name some_one, it shows no record found

enter image description here

Asked By: Albin Saji

||

Answers:

You are searching for the tuple (nn,) in your table names. Just try searching for the string itself like this:

if nn in klm:
Answered By: jprebys

nn=game.replace(" ", "_") has 2 spaces in your code

Try with

nn=game.replace(" ", "_") has one space

game=input("enter student name to update report card: ")
nn=game.replace(" ", "_")
print(nn)
#output
enter student name to update report card: some one
some_one
Answered By: Talha Tayyab
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.