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")
2 Answers
+ 1
else:
("print 3")
should be:
else:
print(3)
**it will always print 3 though since you are comparing an integer to strings
+ 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