Find the number of positive elements in the given list-Python(Питон)

To find the number of positive elements in a given list, you can use the following Python program:

list1 = [12, -7, 5, 64, -14]
count = 0

for num in list1:
    if num >= 0:
        count += 1

print("The number of positive elements in the list is:", count)

This program initializes a variable count to 0. It then iterates through each element in the list using a for loop and checks if the number is greater than or equal to 0. If the condition is true, it increments the count variable by 1. Finally, it prints the value of count, which represents the number of positive elements in the list.

The output for the given list [12, -7, 5, 64, -14] will be:

The number of positive elements in the list is: 3

Please note that this program assumes that the list contains only numeric elements. If the list contains non-numeric elements, you may need to add additional checks to handle those cases.

Leave a Comment