0

What's wrong in this

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("Okay") Please tell in deatil

20th Apr 2020, 6:11 AM
Eco Fico
Eco Fico - avatar
3 Antworten
+ 1
Kindly use relevant tags
20th Apr 2020, 6:19 AM
Muhammad Bilal
Muhammad Bilal - avatar
0
try using elif instead of else if.
20th Apr 2020, 6:16 AM
Dan Audi
0
Hi eco fico. There are several problem in your code... 1. You are making the code more COMPLICATED to understand by not using ELIF instead of such a nested if and else structure. 2. This program is printing okay as it should, because according to the conditions - a. if num == 5 returns false b. then in the else, if num == 11 returns false c. then in the "else of else", if num "!=" 7 returns false since it is 7 d. prints "okay" in the ELSE OF ELSE OF ELSE. At last, dear make programs with elif and less complicated...
20th Apr 2020, 11:00 AM
Varun Vaswani
Varun Vaswani - avatar