-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.py
More file actions
55 lines (49 loc) · 1.59 KB
/
calculator.py
File metadata and controls
55 lines (49 loc) · 1.59 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
#define the functions needed: add, sub, mul, div
#print options to the user
#ask the user for values
#call the functions
#while loop to continue the program until the user wants to exit
def add(a, b):
answer = a + b
print(str(a) + " + " + str(b) + " = " + str(answer) + "\n")
def sub(a, b):
answer = a - b
print(str(a) + " - " + str(b) + " = " + str(answer) + "\n")
def mul(a, b):
answer = a * b
print(str(a) + " * " + str(b) + " = " + str(answer) + "\n")
def div(a, b):
answer = a / b
print(str(a) + " / " + str(b) + " = " + str(answer) + "\n")
while True:
print("a. Addition")
print("b. Subtraction")
print("c. Multiplication")
print("d. Division")
print("e. Exit")
print("")
choice = input("Input your choice: ")
if choice == 'a' or choice == 'A':
print("Addition")
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
add(a, b)
elif choice == 'b' or choice == 'B':
print("Subtraction")
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
sub(a, b)
elif choice == 'c' or choice == 'C':
print("Multiplication")
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
mul(a, b)
elif choice == 'd' or choice == 'D':
print("Division")
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
div(a, b)
else:
choice == 'e' or choice == 'E'
print ("Program ended")
quit()