Write a program to read n numbers from a user and print : ● Number of positive numbers. ● Number of negative numbers. ● Number of zeros. ● Number of odd numbers. ● Number of even numbers. ● Average of all numbers.
n = int(input("Enter the number of element :"))
numbers = []
print(f"Enter {n} numbers")
for i in range(n):
num = int(input(""))
numbers.append(num)
positive_count = 0
negative_count = 0
zero_count = 0
odd_count = 0
even_count = 0
total_sum = 0
for num in numbers:
if num > 0:
positive_count += 1
elif num < 0:
negative_count += 1
else:
zero_count += 1
if num % 2 == 0:
even_count += 1
else:
odd_count += 1
total_sum += num
if n != 0:
average = total_sum / n
else:
average = 0
print(f"Number of positive numbers: {positive_count}")
print(f"Number of negative numbers: {negative_count}")
print(f"Number of zeros: {zero_count}")
print(f"Number of odd numbers: {odd_count}")
print(f"Number of even numbers: {even_count}")
print(f"Average of all numbers: {average:.2f}")
output:
Enter the number of element :5
Enter 5 numbers
1
-2
0
1
2
Number of positive numbers: 3
Number of negative numbers: 1
Number of zeros: 1
Number of odd numbers: 2
Number of even numbers: 3
Average of all numbers: 0.40
Comments
Post a Comment