def inputcheck(n): while True: try: return float(n) except: print("输入错误,输入值只能为数字:") n = input() def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): return x / y def main(): print("Select operation.", "1.Add", "2.Subtract", "3.Multiply", "4.Divide") choice = input("Enter choice(1/2/3/4):") num11 = input("Enter first number: ") num1 = inputcheck(num11) num22 = input("Enter second number: ") num2 = inputcheck(num22) if choice == '1': print(num1, "+", num2, "=", add(num1, num2)) elif choice == '2': print(num1, "-", num2, "=", subtract(num1, num2)) elif choice == '3': print(num1, "*", num2, "=", multiply(num1, num2)) elif choice == '4': if num2 == 0: print("division by zero !") else : print(num1, "/", num2, "=", divide(num1, num2)) else : print("Invalid input") if __name__ == '__main__': main()