Ayesha rajpoot
@ayesharajpoot-1 Tasks: 39
๐ ๏ธ 1 tool
๐ 75 karma
Enthusiast
Joined: October 2024
Follow
Ayesha rajpoot's tools
-
2273560Released 1y ago100% Free```python 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 "Error: Division by zero" return x / y print("Simple Calculator") print("1. Add") print("2. Subtract") print("3. Multiply") print("4. Divide") while True: choice = input("Enter choice (1/2/3/4): ") if choice in ('1', '2', '3', '4'): num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) if choice == '1': print(f"{num1} + {num2} = {add(num1, num2)}") elif choice == '2': print(f"{num1} - {num2} = {subtract(num1, num2)}") elif choice == '3': print(f"{num1} * {num2} = {multiply(num1, num2)}") elif choice == '4': print(f"{num1} / {num2} = {divide(num1, num2)}") else: print("Invalid input") again = input("Do you want to perform another calculation? (yes/no): ") if again.lower() != 'yes': break print("Thank you for using the calculator!") ``` This simple calculator program does the following: 1. Defines functions for basic arithmetic operations: add, subtract, multiply, and divide. 2. Presents a menu for the user to choose an operation. 3. Takes two numbers as input from the user. 4. Performs the selected operation and displays the result. 5. Asks if the user wants to perform another calculation. 6. Continues until the user chooses to exit. You can run this script, and it will allow you to perform basic calculations. Feel free to ask if you have any questions or if you'd like to add more features to the calculator!
