gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
我想用python 寫一個範例
- User
我想用python 寫一個範例
- Assistant
當然可以!以下是一個示範,可以產生一個簡單的計算器,執行基本的四則運算:
def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): if b == 0: return "無法除以零" else: return a / b print("歡迎使用簡單計算器!") operand1 = float(input("請輸入第一個數字:")) operand2 = float(input("請輸入第二個數字:")) print("請選擇您要執行的運算:") print("1. 相加") print("2. 相減") print("3. 相乘") print("4. 相除") choice = int(input("請輸入選項(1/2/3/4):")) result = None if choice == 1: result = add(operand1, operand2) elif choice == 2: result = subtract(operand1, operand2) elif choice == 3: result = multiply(operand1, operand2) elif choice == 4: result = divide(operand1, operand2) else: print("無效的選項") if result is not None: print("結果:", result)你可以根據自己的需求進行修改和擴充,增加更多的運算方式或其他功能。希望這能幫助到你!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.