0

Create program to determine odd or even numbers. Double if even, triple if odd. Return 0, if 0

Here is what I came up with number = int(input()) if number % 2 == 0: print ( number ** 2) elif number % 2 > 0: print ( number ** 3) elif number == 0: print ( 0 ) For some reason it states that if the input is 1 it doesn't work/ meet test 1 criteria. It also does not meet test 4 and 5 EDIT: Toni and Mohan thank you! That helped! Calvin thank you for taking the time to create the one liner but it was about if/ else/ elif statements.

18th May 2021, 8:23 AM
Faz 'Straps' Zaf
Faz 'Straps' Zaf - avatar
4 Respuestas
+ 1
Uhmm or just use one asterisk * It works but it prints wrong
18th May 2021, 8:37 AM
Toni Isotalo
Toni Isotalo - avatar
+ 2
Faz 'Straps' Zaf You have already received some good advice, but I thought you might wish to streamline your concept. num = int(input()) if num%2: print(num *3) else: print(num *2)
18th May 2021, 10:03 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Faz 'Straps' Zaf Change the line three elif number%2==1:
18th May 2021, 8:32 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
0
Here's a one-liner that would work: print(((n:=int(input()))*2)*(n&1<1)+(n*3)*(n&1)) # Hope this helps
18th May 2021, 8:47 AM
Calvin Thomas
Calvin Thomas - avatar