How to put with using "if" and "elif" more then two different adnotations, depend of users number choice? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to put with using "if" and "elif" more then two different adnotations, depend of users number choice?

I have code: if x+y <= 20: print("ok") elif x+y >= 21: print("better") And it is working fine but i want to have something like that, or even more options with adnotations to choose: if x+y <= 20: print("ok") elif x+y >= 21 and x+y <=50: print("better") elif x+y >=51: print("the best") How to do that?

16th Sep 2020, 6:16 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar
4 Answers
+ 3
If I understand your question, what you've written is perfectly fine. Have you tested it?
16th Sep 2020, 6:26 PM
Russ
Russ - avatar
+ 1
You can probably just do elif x+y <= 50: since x+y will automatically be >= 21 if it is not <= 20 (assuming x+y is an integer). I can think of no other reason it wants you to simplify.
16th Sep 2020, 7:43 PM
Russ
Russ - avatar
0
Yes, and the interpreter underline x+y >= 21 and x+y <=50: he want me to simplify
16th Sep 2020, 7:24 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar
0
Ok thank You:)
16th Sep 2020, 7:45 PM
Martyna Tomaszewska
Martyna Tomaszewska - avatar