下面这段代码,我觉得还不错,可以,阅读起来比较happy轻松容易
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): if y != 0: return x / y else: return "错误:被除数不能为零" while True: print("选项:") print("1.加") print("2.减") print("3.乘") print("4.除") print("5.退出") choice = input("键入选项(1-5): ") if choice == '5': break num1 = float(input("输入第一个数字:")) num2 = float(input("输入第二个数字:")) if choice == '1': print("Result:", add(num1, num2)) elif choice == '2': print("Result:", subtract(num1, num2)) elif choice == '3': print("Result:", multiply(num1, num2)) elif choice == '4': print("Result:", divide(num1, num2)) else: print("无效的输入") 再下面这段代码,也比较容易阅读,比较简单,但我觉得没上面那段代码happy 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 print("选择操作:") print("1. 相加") print("2. 相减") print("3. 相乘") print("4. 相除") choice = input("输入你的选择(1/2/3/4): ") num1 = float(input("输入第一个数字: ")) num2 = float(input("输入第二个数字: ")) 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': print(num1, "/", num2, "=", divide(num1, num2)) else: print("无效的输入") c c++ c# Java Python delphi Pascal perl等等都是高级语言,简单的代码,一般人都能阅读,汇编语言的代码我现在读不懂,比高级语言难读太多了。呵呵呵,加油!!!努力进步!!!!! |