In this Python program, we will learn how to print the negative numbers from the given list.
Here is the source code of the program to print the negative numbers from the given list.
# Python Program to Print the Negative 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("\nNegative 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: 45
Enter the Value of 2 Element: -45
Enter the Value of 3 Element: -85
Enter the Value of 4 Element: -96
Enter the Value of 5 Element: -89
Enter the Value of 6 Element: 56
Original List: [45, -45, -85, -96, -89, 56]
Negative Numbers in the Given List are:
-45 -85 -96 -89
# Python Program to Print the Negative Numbers from the Given List Using While Loop
NumList = []
j = 0
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("\nNegative 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: -78
Enter the Value of 2 Element: 56
Enter the Value of 3 Element: -63
Enter the Value of 4 Element: 45
Enter the Value of 5 Element: 25
Enter the Value of 6 Element: 63
Enter the Value of 7 Element: 45
Original List: [-78, 56, -63, 45, 25, 63, 45]
Negative Numbers in the Given List are:
-78 -63
Comments