我正在使用python中的计算器作为我的课堂作业之一(基本运算,加法,减法,乘法和除法)我有一个打印菜单,用户可以从中选择他们想要使用的操作......然后输入他们的整数和答案的打印语句。我的问题是我需要重复用户想要执行的操作的初始输入。编程新手,非常感谢任何帮助。
这是我的代码:
print ("1 = addition")
print ("2 = subtraction")
print ("3 = multiplication")
print ("4 = division")
print ("5 = Exit program\n")
x = int (input ("What operation would you like to perform?: ")) #prompts user for operation
if (x == 1): #if operation chose is addition then this line will exacute
int1 = input ("Enter first integer: ")
int1 = int (int1)
int2 = input ("Enter second integer: ")
int2 = int (int2)
sum = int1 + int2
print ("Sum is:", sum)
elif (x == 2): #if operation chose is subtraction then this line will exacute
int1 = input ("Enter first integer: ")
int1 = int (int1)
int2 = input ("Enter second integer: ")
int2 = int (int2)
dif = int1 - int2
print ("Difference is:", dif)
elif (x == 3): #if operation chose is multiplication then this line will exacute
int1 = input ("Enter first integer: ")
int1 = int (int1)
int2 = input ("Enter second integer: ")
int2 = int (int2)
mult = int1 * int2
print ("Multiplication is:", mult)
elif (x == 4): #if operation chose is division then this line will exacute
int1 = input ("Enter first integer: ")
int1 = int (int1)
int2 = input ("Enter second integer: ")
int2 = int (int2)
div = int1 / int2
print ("Division is: %.2f" % div)
elif (x == 5):
print ("goodbye")
quit()