I am learning python3 and I've hit a blocker regarding an exercise I am doing.
Here is the problem I am trying to solve:
"Write a program which repeatedly reads numbers until the user enters "done". Once "done" is entered, print out the total, count, and average of the numbers. If the user enters anything other than a number, detect their mistake using try and except and print an error message and skip to the next number."
Here is my answer:
numslist = list()
while True:
x = input("Enter a number: ")
numslist.append(x)
if x is str:
print ("bad data")
if x == 'done':
break
numslistt = numslist[0:-1]
count = 0
for a in numslistt:
count = count + 1
total = 0
for thing in numslistt:
total = total + thing
print(numslistt)
print(count)
print(total)
I get an error however when trying to add the numbers in the list? Can someone advise on what I am doing wrong?
Here is the Traceback I get:
Traceback (most recent call last):
File "test.py", line 19, in <module>
total = total + thing
TypeError: unsupported operand type(s) for +: 'int' and 'str'
Thanks,
Samuel