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.
4 RĂ©ponses
+ 1
Uhmm or just use one asterisk *
It works but it prints wrong
+ 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)
+ 1
Faz 'Straps' Zaf
Change the line three
elif number%2==1:
0
Here's a one-liner that would work:
print(((n:=int(input()))*2)*(n&1<1)+(n*3)*(n&1))
# Hope this helps