"Make a list and write a program that adds an integer when it is entered and outputs the average value of the list each time. At this time, if you enter 'don', the program ends." I'm solving this problem, but when I enter the last done, an error appears at the end.
num= [30, 29, 47, 10, 78]
while True:
a = int (input ("number to add?)) #Accept a number to add
num.append(a) # Add accepted numbers using append among methods
plus = sum(num) # Add together
average = plus / len(num) #divide the sum plus by the total number of num using len(num)
print(average)
if (a == done):
break
NameError Traceback (most recent call last)
<ipython-input-31-142603ca28f3> in <module>()
6 average = plus / len(num) #Divide the sum plus by the total number of num using len(num)
7 print(average)
----> 8 if (a == done):
9 break
NameError: name 'done' is not defined
I think the problem is that done is not int, so how can I solve it?
python
You're confusing variables with strings.
done is just a variable. "done" is a fixed string.
© 2024 OneMinuteCode. All rights reserved.