-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_calculator.py
More file actions
31 lines (26 loc) · 1.01 KB
/
basic_calculator.py
File metadata and controls
31 lines (26 loc) · 1.01 KB
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
30
31
def basic_calculator():
while True:
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
operation = input("Enter the operation (+, -, *, /): ")
if operation == '+':
result = num1 + num2
elif operation == '-':
result = num1 - num2
elif operation == '*':
result = num1 * num2
elif operation == '/':
if num2 != 0:
result = num1 / num2
else:
result = "Error! Division by zero."
else:
result = "Invalid operation!"
print(f"The result is: {result}")
except ValueError:
print("Invalid input! Please enter numeric values.")
again = input("Do you want to perform another calculation? (yes/no): ")
if again.lower() != 'yes':
break
basic_calculator()