Python program to Count Positive and Negative Numbers in a List

NumList = []
Positive_count = 0
Negative_count = 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 Entered by the User
print("\nList Entered By the User: ",NumList)
for j in range(Number):
    if(NumList[j] >= 0):
        Positive_count = Positive_count + 1
    else:
        Negative_count = Negative_count + 1
print("\nTotal Number of Positive Numbers in this List =  ", Positive_count)
print("Total Number of Negative Numbers in this List = ", Negative_count)

OUTPUT:

Enter the Total Number of List Elements: 6
Enter the Value of 1 Element: 12
Enter the Value of 2 Element: 63
Enter the Value of 3 Element: -65
Enter the Value of 4 Element: -56
Enter the Value of 5 Element: 32
Enter the Value of 6 Element: -54
List Entered By the User:  [12, 63, -65, -56, 32, -54]
Total Number of Positive Numbers in this List =   3
Total Number of Negative Numbers in this List =  3

Leave a Comment