+ 1
If we use if -elif statement with 'or' - 'and' in it then it isn't executed correctly. Why?
4 ответов
+ 5
Japjot Singh Chauhan , please describe what should the output should be for input = "x" and for input = "y". thanks.
i have put together 3 code version, i think the last one is the desired code. see what happens when you swap the x and y as shown in the code.
https://code.sololearn.com/cuhr26GdwWB3/?ref=app
+ 2
Japjot Singh Chauhan Can you post the code that leads to your Question
Edit : Q edited
+ 1
Ok
+ 1
a=input()
if a==(('x')or('y')):
print('executed')
elif a=="r" or "s":
print("elif block is excuted successfully!")
else:
print('nope')
# Japjot Singh Chauhan try this.. it works as u expected
'''
if you use 'and' then the elif block will only excute if both conditions are True
>>> True and True
True
>>>True and False
False
# using 'or' 👇
>>>True or True
True
>>>True or False
True
'''