0
If i put user == 'Q' only in the if block !! then it loops and works but if i write user == 'Q' or 'q' then it fails why??
#take.txt already exist in the same folder !! with open('take.txt', 'a') as ask: a = True while a: user = input('Why do you like programming?\n(Type Q to quit)\n') if user == 'Q' or 'q': break ask.write(user)
4 ответов
+ 2
If user == "Q" or user =="q":
Everybody comes across that bug on his coding journey
😉
+ 1
I
"q"
evaluates True because "q" is a not empty string.
If user == "Q" or "q":
Is therefore always true.
Some better opportunities might be
If user.lowercase() =="q"# oops was it lowercase?
Or
If user in["Q","q"]:
Just as u want
0
Thank you oma falk!! but why not user == 'Q' or 'q'?? please explain
0
I didn't understand but its ok!!