-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcalculator.py
More file actions
63 lines (49 loc) · 1.34 KB
/
calculator.py
File metadata and controls
63 lines (49 loc) · 1.34 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
Simple Menu-Driven Calculator
Part of Git & GitHub Hands-on Workshop
Organized by Algon DC GCEK
Date: November 8, 2025
"""
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
# TODO: Implement this function
def divide(a, b):
pass
# TODO: Implement this function
def power(a, b):
pass
while True:
print("\n---- CALCULATOR MENU ----")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Power")
print("6. Exit")
choice = input("Enter your choice (1-6): ")
if choice == '6':
print("Exiting... Byeee !!")
break
if choice not in ['1', '2', '3', '4', '5']:
print("Invalid choice! Please try again.")
continue
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input! Please enter numeric values.")
continue
if choice == '1':
print("Result:", add(num1, num2))
elif choice == '2':
print("Result:", subtract(num1, num2))
elif choice == '3':
print("Result:", multiply(num1, num2))
elif choice == '4':
print("Result:", divide(num1, num2))
elif choice == '5':
print("Result:", power(num1, num2))