Python Program To Print Even and Odd numbers from 1 to 100

In this tutorial, we will discuss python program to print even and odd numbers from 1 to 100  and this python program we are going to learn the concept of print even and odd number form 1 to 100 in the python language.

Python Program To Print Even and Odd numbers from 1 to 100

Print even numbers between 1 to 100 using a for loop

we are going to learn how to print number between 1 to 100 using while loop

 

# Python program to print Even Numbers in given range
  
start, end = 1, 100
  
# iterating each number in list
for num in range(start, end + 1):
      
    # checking condition
    if num % 2 == 0:
        print(num, end = " ")

Here the Out Put of python program.

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 

Python program to calculate sum of odd and even numbers using for loop

Here The python program we are going to learn how to calculate sum of odd and even numbers using for loop.

#Python program to calculate sum of odd and even numbers using for loop
max=int(input("please enter the maximum value: "))
even_Sum=0
odd_Sum=0
for num in range(1,max+1):
    if (num%2==0):
        even_Sum=even_Sum+num
    else:
        odd_Sum=odd_Sum+num
print("The sum of Even numbers 1 to {0} = {1}".format(num,even_Sum))
print("The sum of odd numbers 1 to {0} = {1}".format(num,odd_Sum))

Below the output of this program.

please enter the maximum value: 100
The sum of Even numbers 1 to 100 = 2550
The sum of odd numbers 1 to 100 = 2500

Python Program How To Calculate the sum of odd and even numbers using while loop

This python program to we are going to calculate the sum of odd and even number using while loop.

 

#Python program to calculate sum of odd and even numbers using while loop
max=int(input("please enter the maximum value: "))
even_Sum=0
odd_Sum=0
num=1
while (num<=max):
    if (num%2==0):
        even_Sum=even_Sum+num
    else:
        odd_Sum=odd_Sum+num
    num+=1
print("The sum of Even numbers 1 to entered number", even_Sum)
 print("The sum of Even numbers 1 to entered number", odd_Sum)

Below the output of python program

<pre class=”wp-block-code”><code>please enter the maximum value: 500
The sum of Even numbers 1 to entered number 62750
The sum of odd numbers 1 to entered number 62500</code></pre>

 

Leave a Comment

Verified by MonsterInsights