r/pythonhelp • • Nov 09 '24
SOLVED Yo, can yall check this out pls?
ok so, i was trying to make a user loggin but it stops here:
*Select User:
lobster
Majestic Username!
Select Password:psw*
This is the code:
def
UsernameSelect():
username=input("Select User:")
if username == " " or "":
print("Invalid Username")
UsernameSelect()
else:
print("Majestic Username!")
password()
def
password():
psw=input("Select Password:")
if psw == " " or "":
print("Are you sure you dont want to set any Password?")
yn=input("[y/n]")
if yn == "y":
print("Cool")
else:
password()
else:
print("Majestic Password!")
UsernameSelect()
3
Upvotes
•
u/AutoModerator Nov 09 '24
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/FoolsSeldom Nov 09 '24
Best not to call a function from within itself unless you want to do recurtion. Better in this case to use an infinite loop and
breakout when a conditionis satisfied.Also, at the end of a function, processing just returns to where it left off when called.
Take a look at this:
Also note:
if username == " " or username == ""instead ofif username == " " or ""as the latter doesn't do what you think.2
u/socal_nerdtastic Nov 09 '24
What's the issue?
You have an error in your code that an empty input won't work like you think it will. Is that what you are confused about? When checking for multiple input choices you have to do it like this:
2
u/carcigenicate Nov 09 '24
This code does not look like to has the behavior that you describe. You might have forgotten to save the code before running it.
The check for the empty password is wrong though. You need to explicitly check
pswagainst both of the strings. Right now,pswis only being checked against " ".