-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
29 lines (25 loc) · 829 Bytes
/
calculator.py
File metadata and controls
29 lines (25 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Basic Calculator Program
# Ask user for the first number
num1 = float(input("Enter the first number: "))
# Ask user for the second number
num2 = float(input("Enter the second number: "))
# Ask user for the operation
operation = input("Enter an operation (+, -, *, /): ")
# Perform calculation based on the operation
if operation == '+':
result = num1 + num2
print(f"{num1} + {num2} = {result}")
elif operation == '-':
result = num1 - num2
print(f"{num1} - {num2} = {result}")
elif operation == '*':
result = num1 * num2
print(f"{num1} * {num2} = {result}")
elif operation == '/':
if num2 != 0:
result = num1 / num2
print(f"{num1} / {num2} = {result}")
else:
print("Error: Cannot divide by zero.")
else:
print("Invalid operation. Please enter one of: +, -, *, /")