- 1

I have been trying to solve this Python "Depending on Parity" problem for two days straight and have no idea what to do now.

The problem : elif Statements 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 Sample Input: 1 Sample Output: 3 An integer is even if it is divisible by two and odd if it is not even. My codes : 1). number = input() #your code goes here even = number % 2 == 0 odd = number % 2 != 0 if even: print(number * 2) elif odd: print(number * 3) else: print(0) 2). 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) else: print(0) Any suggestions will be greatly appreciated.

9th Feb 2021, 2:34 PM
Kirill Chernyatin
Kirill Chernyatin - avatar
8 Respostas
+ 4
Кирилл Чернятин input() function default return type in string , convert the value to integer first by using int(input())
9th Feb 2021, 2:41 PM
Abhay
Abhay - avatar
+ 3
Here's a suggestion : You don't even need to evaluate if number is equal to zero or not as it will always pass the first *if* condition and will print (0*2) which is also zero.
9th Feb 2021, 3:23 PM
Arsenic
Arsenic - avatar
+ 1
Abhay Holy Toledo. It worked ! I have realized my mistake , thank you for information & have a great day ! :D.
9th Feb 2021, 2:45 PM
Kirill Chernyatin
Kirill Chernyatin - avatar
+ 1
You are welcome , have a nice day as well :)
9th Feb 2021, 2:46 PM
Abhay
Abhay - avatar
+ 1
Abhay Thank you ! :D.
9th Feb 2021, 2:46 PM
Kirill Chernyatin
Kirill Chernyatin - avatar
+ 1
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) else: print(0) easiest way to solved is there !!!!!!! Look here man !
6th Dec 2021, 6:49 PM
Abhishek Gosavi
Abhishek Gosavi - avatar
0
Arsenic Huh. Yeah , that's actually a really solid advice. Thank you for information ! :).
9th Feb 2021, 3:24 PM
Kirill Chernyatin
Kirill Chernyatin - avatar
0
num=int(input('Enter the number: ')) if(num%2==0 and num!=0): num=num*2 print('Double of given number is ',num) elif(not num%2==0 and num!=0): num=num*3 print('Triple of given number is ',num) else: print('0')
21st Dec 2021, 3:50 PM
SANVIKA