0

What did i do wrong? (python pro question)

num = 1 if num is == ("even"): print("double") elif num == ("odd"): print("triple") elif num == ("zero"): print("0") else: ("print 3")

11th Dec 2020, 11:45 AM
Nola Born
2 Respostas
+ 1
else: ("print 3") should be: else: print(3) **it will always print 3 though since you are comparing an integer to strings
11th Dec 2020, 11:51 AM
Slick
Slick - avatar
+ 1
Slick is right👍 But Ive noticed some other mistakes too. ●Variable num is an INTEGER, and if you want to know if it is EVEN, you can use ▶"if num % 2 == 0"◀ this checks if a number divided by 2 has a REMAINDER, if it has none, then it is divisible by 2 (even). If it has remainder "1" then it is ODD. ●Number "0" will also meet the condition of ▶"if num % 2 == 0"◀thats why I instead put the condition "if num == 0" at the TOP so that it will be CHECKED by the program FIRST and will not be USELESS. ●Lastly, Your ELSE statement is UNNECCESSARY. Since, no integer will be NEITHER odd or even. https://code.sololearn.com/ciXx62b1mGlv/?ref=app
11th Dec 2020, 12:03 PM
noteve
noteve - avatar