Program to display even and odd numbers without if
- Home
- Find elements
- Program to display even and odd numbers without if
- On
- By
- 0 Comment
- Categories: Find elements
Program to display even and odd numbers without if
program to display even and odd numbers without if
In this program, we will discuss the concept of program to display even and odd numbers without if statement in Python
In this post, we are going to learn how to display even and odd numbers without using if statement in Python programming language.
First, we must understand how to identify even and odd numbers
What is Even or Odd
When the number is divided by 2 and the balance becomes zero and the above number is called as the even number – eg 2,4,6,8,10
and on the other sides when it is divided by 2 and balance becomes 1 they are called odd numbers or uneven numbers
eg- 1, 3, 5, 7, 9
In my previous post, I have explained the various approaches to display even or odd numbers using if statements in Python language
here, we will discuss how to display odd and even numbers without if statements in Python programming language
There are four programs given below
Print even numbers using for loop in Python
Program 1
The program allows the user to enter the maximum number for display all even numbers using for loop in Python
It will display the even numbers without using if statements.
#print even number using Python for loop num=int(input("Enter the maximum: ")) for i in range(2,num,2): print (i),
When the above code is executed, it produces the following results
Enter the maximum: 30 2 4 6 8 10 12 14 16 18 20 22 24 26 28
Print odd numbers using for loop in Python
Program 2
The program allows the user to enter the maximum number for display all odd numbers
It will display the odd numbers without using if statements.
#print even number using Python for loop num=int(input("Enter the maximum: ")) for i in range(1,num,2): print (i),
When the above code is executed, it produces the following results
Enter the maximum: 30 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
Program 3
Print even numbers using while loop in Python
The program allows the user to enter the maximum number for display all even numbers using while loop in Python
Then, it will display the even and odd numbers without using if statements.
#print even number using Python for loop num=int(input("Enter the maximum: ")) i=2 while i<=num: print (i), i=i+2
When the above code is executed, it produces the following results
Enter the maximum: 26 2 4 6 8 10 12 14 16 18 20 22 24 26
Program 4
Print odd numbers using while loop in Python
The program allows the user to enter the maximum number for display all odd numbers
Then, it will display the even and odd numbers without using if statements in Python language
Program 2
#print even number using Python for loop num=int(input("Enter the maximum: ")) i=1 while i<=num: print (i), i=i+2
When the above code is executed, it produces the following results
Enter the maximum: 40 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
Similar post
Display even and odd numbers without if statement in C++
Display even and odd numbers without if statement in Java
Display even and odd numbers without if statement in C
Suggested for you