160k views
4 votes
write a program that reads in 10 integer numbers. your program should do the following things: determine the number positive or negative count the numbers of positive numbers, and negative calculate the sum of all the numbers calculate the average of all the numbers. find the largest and smallest numbers entered. to simplify your program, you can write a separate program to find the largest and smallest number. the user enters the ten numbers just once each and the user can enter them in any order. your program should not ask the user to enter the positive numbers and the negative numbers separately.

1 Answer

1 vote

Answer: Sure, here's a Python program that reads in 10 integer numbers and performs the specified calculations:

Step-by-step explanation:

Python

Copy code

numbers = []

positive_count = 0

negative_count = 0

positive_sum = 0

negative_sum = 0

# read in 10 integer numbers

for i in range(10):

num = int(input("Enter an integer: "))

numbers.append(num)

# determine positive or negative and count

for num in numbers:

if num >= 0:

positive_count += 1

positive_sum += num

else:

negative_count += 1

negative_sum += num

# calculate sum and average

total_sum = sum(numbers)

average = total_sum / len(numbers)

# find largest and smallest numbers

largest = max(numbers)

smallest = min(numbers)

# output results

print("Positive count:", positive_count)

print("Negative count:", negative_count)

print("Positive sum:", positive_sum)

print("Negative sum:", negative_sum)

print("Total sum:", total_sum)

print("Average:", average)

print("Largest:", largest)

print("Smallest:", smallest)

In this program, we first create an empty list numbers to store the 10 integer numbers entered by the user. We then use a for loop to read in each number and append it to the list.

Next, we use another for loop to determine whether each number is positive or negative, and to count the number of positive and negative numbers. We also calculate the sum of positive and negative numbers separately.

After that, we calculate the total sum and average of all the numbers using the built-in sum and len functions. Finally, we find the largest and smallest numbers using the max and min functions.

Finally, we output all the results using print.

SPJ11

User Koekenbakker
by
8.2k points