- 1

Why code is not working?

number = int(input()) if number / 2: print(number ** 2) elif number / 3: print(number ** 3) Напишите программу, которая берет число в качестве ввода и - возвращает удвоенное число, если оно четное - возвращает утроенное число, если оно нечетное - возвращает 0, если число равно 0 Пример ввода: 1 Пример вывода: 3

6th Feb 2021, 11:14 AM
qwerty80
qwerty80 - avatar
6 Respuestas
+ 1
if just decides whether the code next to it is true or false and based on it proceeds to the following indented line
6th Feb 2021, 11:23 AM
Tomas Konecny
+ 1
Can u translate the text to english, please?
6th Feb 2021, 11:18 AM
Tomas Konecny
+ 1
If you want to check if a number is even or odd, then you have to use modulus operator (%) comparing to 0 remainder. 12 % 2 ---> 0 Since there is no remainder, 2 is a factor of 12, therefore 12 is even. 15 % 2 ---> 1 Since there is a remainder, 15 is not an even number. - - - - - - - - - - - - - - - - - number = int(input()) if number % 2 == 0: print(number ** 2) else: print(number ** 3)
6th Feb 2021, 11:19 AM
noteve
noteve - avatar
0
Write a program that takes a number as input and - returns doubled number if it is even - returns tripled number if odd - returns 0 if number is 0 Input example: 1 Output example: 3
6th Feb 2021, 11:31 AM
qwerty80
qwerty80 - avatar