Reputation: 1
Just wondering how I would store the inputs for an average sum of square roots problem.
The user can input as many numbers as they until they type 'end'
here is what i have for that
while(True):
x = input("Enter a number please:")
if x == 'end':
break
Upvotes: 0
Views: 123
Reputation: 3621
If you mean that you want to store all the x values given, just use a list. l = [] l.append(x).
Upvotes: 0
Reputation: 11625
You can append these values to a list. Sum and then divide by the length for the average.
nums = []
while True:
x = input("Enter a number:")
if x == 'end':
avg = sum(nums) / len(nums)
print("And the average is....", avg)
break
elif x.isdigit():
nums.append(int(x))
else:
print("Try again.")
Upvotes: 3