【发布时间】:2020-05-10 05:41:19
【问题描述】:
我刚开始学习python一周。
我正在尝试做一个测试:
"Beginning of the Program"
print("Hi Sir and welcome to my calculator")
print("Please select from the below menu your math operation")
MenuOption = input("+ for Add, - for Subtract, * for Multiply, / for Division: ")
if (MenuOption != "+" and MenuOption != "-" and MenuOption != "*" and MenuOption != "/"):
print("You have typed wrong character, please try again")
**# my problem is here, I want it to loop back to MenuOption line**
else:
print("Thanks for the correct selection")
FirstNumber = int(input("First Number: "))
SecondNumber = int(input("Second Number: "))
if (MenuOption == "+"):
print(FirstNumber + SecondNumber)
elif (MenuOption == "-"):
print(FirstNumber - SecondNumber)
elif (MenuOption == "*"):
print(FirstNumber * SecondNumber)
elif (MenuOption == "/"):
print(FirstNumber / SecondNumber)
当我不按任何数学符号(+、-、*、/)时,我希望程序开始恢复 MenuOption
【问题讨论】:
标签: python python-3.x