Apologies, first time poster, and beginner python user.
The problem asks the following: Write a Python program that allows the user to enter any number of nonnegative floating-point values. The user terminates the input list with any negative value. The program then prints the sum, average (arithmetic mean), maximum, and minimum of the values entered. The terminating negative value is not used in the computations.
I pretty much have most of it, have tried a few different ways, and can not seem to get it to compute the average and sum correctly. (can not get it without the negative number to terminate, or also makes the average negative, or the same as the sum value)
I am considering starting over and using a def function call. ?? I also was starting to get somewhere with try-except statements, but that fell apart as well.
Any advice in the right direction is appreciated!
First...
num = []
tot = 0
big = None
small = None
while True:
numbers = float(input('Enter a positive number, negative to stop: '))
tot += numbers
if big is None or numbers > big:
big = numbers
if small is None or numbers < small:
small = numbers
if numbers < 0:
break
avg = tot / numbers
print('Sum is:', tot)
print('Average is:',avg)
print('Maximum is:',big)
print('Minimum is:',small)
and if I change a few things I get the average to be positive instead of negative, but still is the same value as minimum, just some snippets...
tot = 0
big = None
small = None
count = 0
while True:
length = count + 1
#etc, etc...then trying to do...
avg = tot/length
#or...
avg =str(tot/length)
but still stuck.