How can I code in a way that it tells my user that the input not available in the database?
Here is my code:
def sql_getage(name):
query = """\
select age from store
where name = '{}'
""".format(name)
results = (execute_read_query (conn, query))
for i in results:
theresult = str(i[0])
return (theresult)
name = input("Please input your username")
age = sql_getage(name)
print("Your age is", age)
My database have 2 columns:
username Age
John 20
Amy 21
How can I code such that if the user inputs name as
Jhn
, And it cannot be found in the database table, then I would print wrong username
Currently if I input the name wrongly, it will still continue to the next code, which is printing the age. And it would print an empty age.