+ 1
Help with Code Coach problem
Here's the problem: Write a program that takes a number as input and - returns its double, if the number is even - returns its triple, if the number is odd - returns 0, if number is 0 Here's my solution: number = int(input()) #your code goes here if number // 2: print(number * 2) elif not number // 2: print(number * 3) elif number == 0: print(number) Out of the five test cases, I'm failing the fourth one for some reason. Please help!
7 Answers
+ 6
number//2 return 1,if Input is 2, return 1 if input is 3.
( a number for all even or odd except for 0) so 1st if True for all numbers except 0. Use % instead of //. And then it works for odd numbers.. So recode with these changes..
+ 3
Thank you!
+ 1
number = int(input())
#your code goes here
if number%2 == 0:
print(numner*2)
elif number%2 == 1:
print(number*3)
elif number == 0:
print(0)
try this
+ 1
number = int(input())
#your code goes here
if number == 0:
print(0)
elif number%2 == 0:
print(number*2)
else:
print(number*3)
0
Thats what I wrote:
number = int(input())
#your code goes here
if number // 2:
print(number + number)
elif not number // 2:
print(number + number + number)
elif num == 0:
print(num)
But the 4th is still failing. Can someone please help me. Thank you!
0
number = int(input())
#your code goes here
if number%2==0:
print(number*2)
elif number%2!=0:
print(number*3)
else:
print(0)
0
A programmer wrote a program to print odd numbers. He wanted to explain how the program works in the code, but he forgot to comment and the program does not work. Comment lines so that it prints the odd numbers.