If we use if -elif statement with 'or' - 'and' in it then it isn't executed correctly. Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

If we use if -elif statement with 'or' - 'and' in it then it isn't executed correctly. Why?

Help...... https://code.sololearn.com/cRyNdwrxsIrU/?ref=app

31st Dec 2020, 1:21 PM
Japjot Singh Chauhan
Japjot Singh Chauhan - avatar
4 Answers
+ 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
31st Dec 2020, 2:54 PM
Lothar
Lothar - avatar
+ 2
Japjot Singh Chauhan Can you post the code that leads to your Question Edit : Q edited
31st Dec 2020, 1:25 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 1
Ok
31st Dec 2020, 1:30 PM
Japjot Singh Chauhan
Japjot Singh Chauhan - avatar
+ 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 '''
31st Dec 2020, 2:11 PM
Ratnapal Shende
Ratnapal Shende - avatar