Help with Code Coach problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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!

28th Dec 2020, 9:58 PM
Zarif Rezwan
Zarif Rezwan - avatar
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..
28th Dec 2020, 10:05 PM
Jayakrishna 🇮🇳
+ 3
Thank you!
28th Dec 2020, 10:12 PM
Zarif Rezwan
Zarif Rezwan - avatar
+ 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
27th Jun 2021, 10:56 PM
Hugues Rodrigue Tha Andela
Hugues Rodrigue Tha Andela - avatar
+ 1
number = int(input()) #your code goes here if number == 0: print(0) elif number%2 == 0: print(number*2) else: print(number*3)
19th Feb 2022, 10:15 AM
Liria
Liria - avatar
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!
27th Jan 2021, 2:13 PM
Andreas
Andreas - avatar
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)
5th Sep 2021, 11:36 PM
Kluivert Boakye Duah
Kluivert Boakye Duah - avatar
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.
23rd Feb 2022, 5:14 AM
Rhian Galzia