In this Python Program, we will learn how to print the positive numbers from the given list.
Here is the source code of the program to print the positive numbers from the given list.
# Python Program to Print the Positive Numbers from the 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("\nPositive Numbers in the Given List are: ")
for j in range(Number):
if(NumList[j] >= 0):
print(NumList[j], end = ' ')
Enter the Total Number of List Elements: 6
Enter the Value of 1 Element: 12
Enter the Value of 2 Element: 52
Enter the Value of 3 Element: 32
Enter the Value of 4 Element: -89
Enter the Value of 5 Element: -56
Enter the Value of 6 Element: 25
Original List: [12, 52, 32, -89, -56, 25]
Positive Numbers in the Given List are:
12 52 32 25
# Python Program to Print the Positive Numbers from the Given List Using For 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("\nPositive Numbers in the Given List are : ")
while(j < Number):
if(NumList[j] >= 0):
print(NumList[j], end = ' ')
j = j + 1
Enter the Total Number of List Elements: 7
Enter the Value of 1 Element : 12
Enter the Value of 2 Element : -54
Enter the Value of 3 Element : -63
Enter the Value of 4 Element : 25
Enter the Value of 5 Element : 65
Enter the Value of 6 Element : -56
Enter the Value of 7 Element : 45
Original List: [12, -54, -63, 25, 65, -56, 45]
Positive Numbers in the Given List are :
12 25 65 45
Comments