Learn Dedaandsons

Story: Python Exercise: even-odd series ; 21-09-2023;

Python Even-Odd number generating program, for Beginners.

Write a python program to calculate the user input number is even or odd?

Even-odd program:

num= input("enter the value to check if it is even or odd: ")

is_even= int(num) % 2 == 0

if is_even == True:

print("even number")

else:

print("odd")

Output:

enter the value to check if it is even or odd: 25

odd

So the program to check if the number (input from user), is a even number or a odd number we would first take input from the user, after this we would calculate the results with the formula: int(num)% 2 == 0

After checking the number is either even or odd, we will put the results in is_even (variable.) Now we have implemented the if else [control flow statement] condition, here: if is_even == True:

If the results in the variable is_even is == (equals to) True, than the first block of code i.e. print("Even number") would be executed, otherwise the second block of code, which we have written under else part will be executed i.e. [that is] print("odd").

Note:

This article may have been created with the assistance of artificial intelligence (AI) tools. Some of the research data used to write this article may have been derived by AI tools, and then put together by humans. Additionally, AI tools may have been used to write some or all of the article.

More?:

Move Back to Top

Like, share, follow us.