+ 3
Why this code always evaluates the first elif statement as true?
I don't understand why this always evaluate only the first elif statement as true, this even when it should be evaluated as false and go to the next statement. I'm using Python 3 https://code.sololearn.com/clMh2gy56Plq/?ref=app
4 Antworten
+ 2
What do 'or' and 'and' statements do? They are called logical operators because they are used to connect two conditions, every condition or expression has a Boolean value, in the Boolean logic, everything rather than 0, "", [], None, False evaluates to True
This means that 'a' or 'b' means True or True, while in: user == 'a' or user == 'b', both user == 'b' and user == 'a' can be either True or False depending on the situation, same thing applies in case of 'and' operator.
+ 6
As already mentioned, syntax has to be:
elif user == "a" or user == "b":
# or could be also expressed like this:
elif user in 'ab':
+ 3
The syntax is:
elif user == 'x' or user == 'y':