i making a terminal sign up website thing - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: i making a terminal sign up website thing (/thread-35452.html) |
i making a terminal sign up website thing - Kenrichppython - Nov-04-2021 code def username(): username = input("username:") print("are you sure thats your username?") YesNo = input("press t if thats your username press f if its not") if YesNo == f: username = input("username:") username() f = f error username:ken are you sure thats your username? press t if thats your username press f if its notf Traceback (most recent call last): File "C:\Users\user\PycharmProjects\pythonProject7\main.py", line 8, in <module> username() File "C:\Users\user\PycharmProjects\pythonProject7\main.py", line 5, in username if YesNo == f: NameError: name 'f' is not defined Process finished with exit code 1 RE: i making a terminal sign up website thing - bowlofred - Nov-04-2021 Please use bbcode tags for your python code (you can press the python button above the editor). (Nov-04-2021, 03:15 AM)Kenrichppython Wrote:if YesNo == f: This code checks if the variable YesNo has the same value as the variable f . But since you haven't assigned to the variable f yet, this is an error. I suspect you wanted to check if it was the string f . If so, you need to use quotes to define the string.if YesNo == "f":It is also a good idea not to use the same name for both a function and a variable in the function. Because they have different scope, this won't break immediately. But there are situations where this would cause confusion. Better to pick different names: def username(): username = input("username:") #username used as function name and string name ... |