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.
- 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