In this python program, we will learn how to print the even numbers from the given list.
Here is the source code of the program to print the even numbers from the given list.
# Python Program to Print the Even Numbers in a Given List Using For Loop
NumList = []
# Take the Input From the User
Number = int(input("Enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Enter the Value of %d Element: " %i))
NumList.append(value)
# Print the List
print("\nOriginal List: ",NumList)
print("\nEven Numbers in the Given List are: ")
for j in range(Number):
if(NumList[j] % 2 == 0):
print(NumList[j], end = ' ')
Enter the Total Number of List Elements: 6
Enter the Value of 1 Element: 5
Enter the Value of 2 Element: 4
Enter the Value of 3 Element: 85
Enter the Value of 4 Element: 42
Enter the Value of 5 Element: 32
Enter the Value of 6 Element: 45
Original List: [5, 4, 85, 42, 32, 45]
Even Numbers in the Given List are:
4 42 32
# Python Program to Print the Even Numbers in a Given List Using While Loop
NumList = []
j = 0
# Take The Input From the User
Number = int(input("Enter the Total Number of List Elements: "))
for i in range(1, Number + 1):
value = int(input("Enter the Value of %d Element: " %i))
NumList.append(value)
# Print the List
print("\nOriginal List: ",NumList)
print("\nEven Numbers in the Given List are: ")
while(j < Number):
if(NumList[j] % 2 == 0):
print(NumList[j], end = ' ')
j = j + 1
Enter the Total Number of List Elements: 6
Enter the Value of 1 Element: 45
Enter the Value of 2 Element: 12
Enter the Value of 3 Element: 52
Enter the Value of 4 Element: 78
Enter the Value of 5 Element: 65
Enter the Value of 6 Element: 35
Original List: [45, 12, 52, 78, 65, 35]
Even Numbers in the Given List are:
12 52 78
Comments