My code:
Basically, I am reading in inputs in a list. It should give an error if its not an integer, and skip that input and stop when i write "done". Then I am creating a count, sum and average, which I print.
total = 0
count = 0
list = []
while True:
num = input("Enter a number: ")
if num == "done":
break
try:
fnum = float(num)
list.append(fnum)
except:
print("Invalid input")
print(fnum, type(fnum))
continue
print(list)
for i in list:
count += 1
total += i
print(total, count, "Average: ", total/count)
Error message
Like I said, it runs fine from Jupyter or Colab, but I get the following error message from cmd:
If I enter a random string:
Traceback (most recent call last):
File "C:location\file.py", line 6, in <module>
num = input("Enter a number: ")
File "<string>", line 1, in <module>
NameError: name 'asd' is not defined
If I enter done:
Traceback (most recent call last):
File "C:location\file.py", line 6, in <module>
num = input("Enter a number: ")
File "<string>", line 1, in <module>
NameError: name 'done' is not defined