-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-calculator.py
53 lines (46 loc) · 1.46 KB
/
simple-calculator.py
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
def options():
print("""
1 - Addition
2 - Subtraction
3 - Multiplication
4 - Division
5 - Exit the program
""")
options()
while True:
choose_option = str(input('Choose your option: ')).strip()
if choose_option == '1':
n1 = float(input('Enter a number (N1): '))
n2 = float(input('Enter a number (N2): '))
def add(x, y):
return x + y
add_result = add(n1, n2)
print(add_result)
elif choose_option == '2':
n1 = float(input('Enter a number (N1): '))
n2 = float(input('Enter a number (N2): '))
def subtract(x, y):
return x - y
subtract_result = subtract(n1, n2)
print(subtract_result)
elif choose_option == '3':
n1 = float(input('Enter a number (N1): '))
n2 = float(input('Enter a number (N2): '))
def multiply(x, y):
return x * y
multiply_result = multiply(n1, n2)
print(multiply_result)
elif choose_option == '4':
n1 = float(input('Enter a number (N1): '))
n2 = float(input('Enter a number (N2): '))
def divide(x, y):
if y == 0:
return "Error: Division by zero is not allowed."
return x / y
divide_result = divide(n1, n2)
print(divide_result)
elif choose_option == '5':
print("Exiting the program.")
break
else:
print("Invalid option. Please choose an option between 1 and 5.")