Finding the sum of a list created by a user

41 Views Asked by At

I am having trouble getting the sum of the list inputted by the user, I have tried multiple ways, I just need help in what I can do to the sum of the list. Thanks, for any help.

import statistics
data=[]
while True:
    num = input("Enter a number (type quit to leave): ")
    data.append(num)
    if num == "quit":
        data.remove("quit")
        break
def Average(data):
    return sum(data) / len(data)

print(*data, sep=", ")
data.sort()
print("The max value entered is: ", max(data))
print("The min value entered is: ", min(data))
print("Sorted list: ", data)
print("First and Last removed: ", (data[1:-1]))
print("The List average is: ", sum(data))
1

There are 1 best solutions below

1
On
data=[]
while True:
   num = input("Enter a number (type quit to leave): ")
   data.append(num)
   if num == "quit":
       data.remove("quit")
       break
for i in range(0, len(data)):
   data[i] = int(data[i])

print(*data, sep=", ")
data.sort()
print("The max value entered is: ", max(data))
print("The min value entered is: ", min(data))
print("Sorted list: ", data)
print("First and Last removed: ", (data[1:-1]))
print("The List average is: ", sum(data))