I really don’t know what I am doing wrong here but whenever I run the code the output doesn’t calculate the variable and only sets it to 0.0
total = 0.0
num1 = 0.0
average = 0.0
while True:
input_num = input("Enter a number ")
if input_num == 'done':
break
try:
num = float(input_num)
except ValueError:
print("Invalid Input")
continue
total = total + num
num1 = num1 + 1
average = total / num1
print("total: ", total)
print("count: ", num1)
print("average: ", average)
I got the following after running the code
[Image of code run]: (https://imgur.com/a/lEz6ibh)
>Solution :
Your code isn’t indented properly, so the code after continue never gets executed. To get it to work, unindent the lines after continue:
total = 0.0
num1 = 0.0
average = 0.0
while True:
input_num = input("Enter a number ")
if input_num == 'done':
break
try:
num = float(input_num)
except ValueError:
print("Invalid Input")
continue
total = total + num
num1 = num1 + 1
average = total / num1
print("total: ", total)
print("count: ", num1)
print("average: ", average)