Elif statements V problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Elif statements V problem

So I am working through the python pro material and it’s been great. I’m stuck on a particular problem though, any tips on how to solve? If the number is even, it gets doubled If the number is odd it gets tripled If the number is 0 it prints 0 number = input() #your code goes here if number % [2] == [0]: print(number * 2) elif number % [2] != [0]: print(number * 3) elif number == [0]: print(0) My code won’t calculate them as separate. I think it’s adding them all. If the input is 5 i think my code returns 117 or something wild. I think it’s supposed to stop if the criteria is met. If it is even, it multiples by two and stops. I don’t think my code is doing that.

19th Jan 2021, 2:59 AM
Steve Barone
Steve Barone - avatar
3 Answers
+ 4
thanks Ipang it was throwing an error with your code, BeegCat did solve the problem with theirs. i figured you dont need to wrap it in brackets but i was hitting errors before and i made some changes and that was one of them and it went away lol. appreciate the help! getting better with practice hehe
19th Jan 2021, 2:11 PM
Steve Barone
Steve Barone - avatar
+ 2
You dont need to wrap the numbers in square brackets, just use the numbers. [2] -> a list object containing an int object (whose value is 2) Not same with 2 (an int object, value is 2) if number == 0: print(number) elif number % 2 == 0: print(number * 2) else: print(number * 3)
19th Jan 2021, 3:41 AM
Ipang
+ 2
number =int(input()) if number%2 == 0: print(number*2) elif number % 2 == 1: print(number * 3) else: print(0)
17th Mar 2022, 4:36 PM
Nadia TALBI
Nadia TALBI - avatar