Try this:
var = int(raw_input("Enter 1,2,3 or 4 for add,subtract,multiplication,division respectively: "))
if var == 1:
print "You chose to add.Lets add!! :)"
def main ():
total = 0.0
while True:
number = float(raw_input('enter a number: '))
total+=number
if number == 0:
break
print 'the total is', total
main()
This will take any input and covert it to a float, add that to your total and, if the input is 0
then return your total.
To make this more flexible you can use the following change that will add all numbers (including 0
) and exit when nothing is entered by the user.
total = float(raw_input('enter a number: '))
while True:
number = raw_input('enter a number: ')
if number == '':
break
total+=float(number)