Why is not working? please with explanations | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is not working? please with explanations

num = 7 if num == 5: print("number is 5") else: if num == 11: print("number is 11") else: if num == 7: print("number is 7") else: print("number is ont anything from 7.11.5")

10th Dec 2016, 9:26 AM
Nodirbek
3 Answers
+ 3
prefer notation like if num == 7: print.... elif num == 5: print .... elif num == 11: print .... else: none of previous case
10th Dec 2016, 9:42 AM
David Pierret
David Pierret - avatar
+ 2
you canot have multiple else for one if. but you can have elif wich is a else + if statement.
10th Dec 2016, 9:43 AM
David Pierret
David Pierret - avatar
0
The nested if statements were obscuring the result, try this: num = 7 if num == 5: print("number is 5") elif num == 11: print("number is 11") elif num == 7: print("number is 7") else: print("number is not anything from 7.11.5")
10th Dec 2016, 9:52 AM
Kerrash
Kerrash - avatar