**I have received a feedback about my Login Authentication code.
I cant think of any other options to satisfy this feedback, aside from ending my code using else statement for any other characters that user may type in. Brains Trust, suggestions please!
Feedback below:
“Make it so the user must select an option in the menu so they can’t input something that is not in the menu that way you can do away with the following lines - If user inputs any character (other than 1,2,3 or 4)
*Else user inputs any other characters in menu (other than 1,2,3 and secret code)”
while True:
print("\n\033[32m", "Welcome - Please login to access your account", "\033[0m", sep="")
menu=input("\nPress 1 - New User \nPress 2 - Existing User\nPress 3 - Delete Account\n\U0001F449 ")
if menu=="1":
NewUser() #new user registration
login() #sign in as current user
break
elif menu == "2":
login() #sign in as current user
break
elif menu =="3":
deleteAccount()
elif menu == "777":
keys = db.keys() #returns all key names in db
for key in keys:
print(f"{key}:{db[key]}") #prints key name and key value
else:
print("Please choose only between the selections above: ")
continue
This is correct. In python, a language without switch/case, the way to do it is either if/elif/else.
there are some other way but overall if/elif/else is the most pythonic (as in preferred by python users)
they added it to the latest python? Such a bad idea … and the behaviours is not the same as this is pattern matching. So for this example is good, but in other cases the order of things might cause havoc in a match/case.
Still great @MiloCat , i missed this change in 3.10
I learned something today, which makes this thread one of my all time fabs now! Gotta play with match/case (maybe even in my sill;y console tetris game) hope reply is 3.10+
I’ve checked the link you shared, and on google. Looks to me that its a lot like similar to the simple If, elif, else statement, especially its the output. It still allows user to enter a value that I didnt define. I’m a noob in Py, so please point out what im missing here.
Well … I will use it anyhow. I always likes switch/case anyhow and while i say you are right and nobody should do what i am about to do. I will still do it