So im extremely new to python. Im teaching it to myself for a school project and i heard that calculators are a good place to start so that's exactly what im doing. I have only been using it for about a day now so like i said im pretty newb. So i have a menu that you choose a certain calculation from such as addition, subtraction, etc. From there you choose how many number you want to add, subtract, etc. Then it gets stuck inside the while loop when i want it to go back to the beginning where the menu is so you can pick a new function without having to restart the program. Here's my code, sorry i know its kinda long:
ans=True
while ans:
print ("""
Please pick one of the following calculations:
(1) Addition
(2) Subtraction
(3) Multiplication
(4) Division
(5) Exit/Quit
""")
ans=raw_input("What would you like to do? ")
#addition
if ans=="1":
ans=raw_input("""
Thanks for choosing addition mode!
How many numbers would you like to add? """)
while ans:
if ans=="2":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
total = a+b
print 'The sum of those numbers is', total
if ans=="3":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
c = raw_input('enter your third number: ')
c = int(c)
total = a+b+c
print 'The sum of those numbers is', total
if ans=="4":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
c = raw_input('enter your third number: ')
c = int(c)
d = raw_input('enter your fourth number: ')
d = int(d)
total = a+b+c+d
print 'The sum of those numbers is', total
if ans=="5":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
c = raw_input('enter your third number: ')
c = int(c)
d = raw_input('enter your fourth number: ')
d = int(d)
e = raw_input('enter your fifth number: ')
e = int(e)
total = a+b+c+d+e
print 'The sum of those numbers is', total
else:
print "Los Siento! Invalid input."
break
#subtraction
if ans=="2" :
ans=raw_input("""
Thanks for choosing subtraction mode!
How many numbers would you like to subtract? """)
while ans:
if ans=="2":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
total = a-b
print 'The difference between those numbers is', total
if ans=="3":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
c = raw_input('enter your third number: ')
c = int(c)
total = a-b-c
print 'The difference between those numbers is', total
if ans=="4":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
c = raw_input('enter your third number: ')
c = int(c)
d = raw_input('enter your fourth number: ')
d = int(d)
total = a-b-c-d
print 'The difference between those numbers is', total
if ans=="5":
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
c = raw_input('enter your third number: ')
c = int(c)
d = raw_input('enter your fourth number: ')
d = int(d)
e = raw_input('enter your fifth number: ')
e = int(e)
total = a-b-c-d-e
print 'The difference between those numbers is', total
#Multiplication
if ans=="3":
print "Thanks for choosing multiplication mode!"
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
total = a*b
print 'The product of those two number is', total
#division
if ans=="4":
print "Thanks for choosing division mode!"
a = raw_input('enter your first number: ')
a = int(a)
b = raw_input('enter your second number: ')
b = int(b)
total = a/b
print 'The qoutient of those two number is', total
#Exit/Quit
if ans=="5":
print "Goodbye!"
break
else:
print "Los Siento! Invalid input."