Write a python program to find whether a given number is odd or even
Answers
Answered by
35
num=int(input())
if num%2==0:
print("Even")
else:
print("odd")
Answered by
4
Here is the logic behind this problem.
If a number is even, it would leave a remainder of 0 when divided by 2 and if the number is odd, it would leave a remainder of more than 0 and that is exactly what we have to check.
Let's first define a function so in that way, it will be easier to to use the program.
def even_odd(num1):
return 'Even' if num%2 == 0 else 'odd'
Now that we have the definition, we just need to take the input from the user.
even_odd(int(input('Enter your number:')))
What we are doing is simply calling the definition named even_odd.
Similar questions
English,
6 months ago
Hindi,
6 months ago
Physics,
1 year ago
Social Sciences,
1 year ago
Chemistry,
1 year ago