Run a simple calculator in the console.
()
| 36 | |
| 37 | |
| 38 | def calculator() -> None: |
| 39 | """Run a simple calculator in the console.""" |
| 40 | print("Select operation.") |
| 41 | print("1.Add\n2.Subtract\n3.Multiply\n4.Divide") |
| 42 | |
| 43 | while True: |
| 44 | choice: str = input("Enter choice (1/2/3/4): ").strip() |
| 45 | if choice in ("1", "2", "3", "4"): |
| 46 | num1: float = float(input("Enter first number: ")) |
| 47 | num2: float = float(input("Enter second number: ")) |
| 48 | |
| 49 | if choice == "1": |
| 50 | print(f"{num1} + {num2} = {add(num1, num2)}") |
| 51 | elif choice == "2": |
| 52 | print(f"{num1} - {num2} = {subtract(num1, num2)}") |
| 53 | elif choice == "3": |
| 54 | print(f"{num1} * {num2} = {multiply(num1, num2)}") |
| 55 | elif choice == "4": |
| 56 | print(f"{num1} / {num2} = {divide(num1, num2)}") |
| 57 | break |
| 58 | else: |
| 59 | print("Invalid Input. Please select 1, 2, 3, or 4.") |
| 60 | |
| 61 | |
| 62 | if __name__ == "__main__": |
no test coverage detected