it goes in a loop but l don’t know how to get it to add the same variable over and over again l don’t know if this sounds stupid or not but l looked all online and couldn’t find anything
my lines of code are below
while True:
number = input("please input first number you’d like: ")
try:
first_number = float(number)
except ValueError:
print("that's not a vaild number ")
continue
finally:
stop = input("would you like the equation to stop ")
if stop == "yes":
print(number)
break
elif stop == "no":
continue
You need to keep the previous result in a variable, then add the new number to it.
For example:
total = 0
while True:
number = input("Please input a number: ")
try:
first_number = float(number)
except ValueError:
print("That's not a valid number")
continue
total += first_number
stop = input("Would you like the equation to stop? ")
if stop == "yes":
print(total)
break
The important part is total += first_number. It keeps adding each new number to the previous total.
Also, you probably don’t want to use finally here, because finally runs even when the conversion fails.