Hi everyone,
I have just programmed a very very simple calculator program, I am actually rather pleased. I would just like to know how I can make it so that every time the user has entered their input and an output has been returned by the program, the program jumps back to the start and ask the user to choose another option. Here is the code for my very very simple calculator program.
Thanks, -Deathwing
I have just programmed a very very simple calculator program, I am actually rather pleased. I would just like to know how I can make it so that every time the user has entered their input and an output has been returned by the program, the program jumps back to the start and ask the user to choose another option. Here is the code for my very very simple calculator program.
Code:
# my first very simple calculator
# this program only does basic arithmatic
print\
"""
#-------------#
# MYCALC 1.0 #
#-------------#
WELCOME TO MYCALC 1.0 This is a command line program that you can use
as a calculator just incase you don't have one installed on your
desk top. Using it is pretty self explanitory.
"""
print " You have the following options:\n"
options = ('addition = 1','subtraction = 2', 'division = 3', 'multiplication = 4',)
print "\nHere are ur options:\n", options
choice = int(raw_input("Plese enter your operation choice: "))
if choice == 1:
a = int(raw_input("enter value a: "))
b = int(raw_input("enter value b: "))
total = a+b
print "\nThe total is:", total
elif choice == 2:
a = int(raw_input("\nenter value a: "))
b = int(raw_input("\nenter value b: "))
total = a-b
print "\nThe total is:", total
elif choice == 3:
a = int(raw_input("\nenter value a: "))
b = int(raw_input("\nenter value b: "))
total = a/b
print "\nThe total is:", total
elif choice == 4:
a = int(raw_input("\nenter value a: "))
b = int(raw_input("\nenter value b: "))
total = a*b
print "\nThe total is:", total
else:
print "\nYour choice is invalid"
raw_input("\nPres enter to exit.")
Comment