Thursday, December 26, 2024
Google search engine
HomeLanguagesPython Program to Print Even and Odd numbers From 1 to N

Python Program to Print Even and Odd numbers From 1 to N

Python program to print even and odd numbers from 1 to N(10, 50 100, 1000); Through this tutorial, you will learn how to print even and odd numbers from 1 to N (10, 100, 500, 1000) using the function, for loop, while loop and if-else statement.

Python Program to Print Even and Odd numbers From 1 to N

  • Algorithm to print even and odd numbers from 1 to N
  • Python Program to Print Odd Numbers from 1 to N using For Loop
  • Python Program to Print Odd Numbers from 1 to N without If Statement
  • Python Program to Print Odd Numbers using While Loop
  • Python Program to Print Even Numbers from 1 to N using For Loop
  • Python Program to Print Even Numbers from 1 to N without If Statement
  • Python Program to Print Even Numbers from 1 to N using While Loop

Algorithm to print even and odd numbers from 1 to N

  • Use the python input() function that allows the user to enter the maximum limit value.
  • Next, Run for a loop and Add the current value of n to num variable.
  • Next, Python is going to print even and odd numbers from 1 to the user entered a maximum limit value.

1: Python Program to Print Odd Numbers from 1 to N using For Loop

# Python Program to Print Odd Numbers from 1 to N

num = int(input(" Please Enter any Maximum Number : "))

for number in range(1, num + 1):
    if(number % 2 != 0):
        print("{0}".format(number))

Output

Please Enter any Maximum Number :  10
1
3
5
7
9

2: Python Program to Print Odd Numbers from 1 to N without If Statement

# Python Program to Print Odd Numbers from 1 to N wihtout using if statement

num = int(input(" Please Enter any Maximum Number : "))

for number in range(1, num + 1, 2):
    print("{0}".format(number))

Output

Please Enter any Maximum Number :  10
1
3
5
7
9

3: Python Program to Print Odd Numbers using While Loop

# Python Program to Print Odd Numbers from 1 to N using while loop

num = int(input(" Please Enter the Maximum Value : "))

number = 1

while number <= num:
    if(number % 2 != 0):
        print("{0}".format(number))
    number = number + 1

Output

Please Enter any Maximum Number :  10
1
3
5
7
9

4: Python Program to Print Even Numbers from 1 to N using For Loop

# Python Program to Print Even Numbers from 1 to N using for loop

num = int(input(" Please Enter the Maximum Number : "))

for number in range(1, num+1):
    if(number % 2 == 0):
        print("{0}".format(number))

Output

Please Enter the Maximum Number :  10
2
4
6
8
10

5: Python Program to Print Even Numbers from 1 to N without If Statement

# Python Program to Print Even Numbers from 1 to N without using if statement

num = int(input(" Please Enter the Maximum Value : "))

for number in range(2, num+1, 2):
    print("{0}".format(number))

Output

Please Enter the Maximum Number :  10
2
4
6
8
10

6: Python Program to Print Even Numbers from 1 to N using While Loop

# Python Program to Print Even Numbers from 1 to N  using while loop

num = int(input(" Please Enter the Maximum number : "))

number = 1

while number <= num:
    if(number % 2 == 0):
        print("{0}".format(number))
    number = number + 1

Output

Please Enter the Maximum Number :  10
2
4
6
8
10

Recommended Python Programs

RELATED ARTICLES

Most Popular

Recent Comments