From 7495d098fc45859022dbaae6f81ea861fdd600d5 Mon Sep 17 00:00:00 2001 From: u011283906 Date: Mon, 17 Jun 2024 18:35:24 +0800 Subject: [PATCH] Auto Commit --- "\350\256\241\347\256\227\346\234\272" | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 "\350\256\241\347\256\227\346\234\272" diff --git "a/\350\256\241\347\256\227\346\234\272" "b/\350\256\241\347\256\227\346\234\272" new file mode 100644 index 0000000..ab85cba --- /dev/null +++ "b/\350\256\241\347\256\227\346\234\272" @@ -0,0 +1,25 @@ +def calculator(): + while True: + num1 = float(input("请输入第一个数字: ")) + operator = input("请输入运算符 (+, -, *, /): ") + num2 = float(input("请输入第二个数字: ")) + + if operator == '+': + result = num1 + num2 + elif operator == '-': + result = num1 - num2 + elif operator == '*': + result = num1 * num2 + elif operator == '/': + result = num1 / num2 + else: + print("无效的运算符") + continue + + print("结果: " + str(result)) + + choice = input("继续计算吗?(y/n): ") + if choice.lower() != 'y': + break + +calculator() -- GitLab