-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_06_basic_calculator.py
64 lines (56 loc) · 1.7 KB
/
project_06_basic_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
54
55
56
57
58
59
60
61
62
63
64
# Project 6
# Basic Calculator
# Must have functions: add, sub, mul, div
def add(a, b):
answer = a + b
print("Result of " + str(a) + " + " + str(b) + " = " + str(answer) + "\n")
def sub(a, b):
answer = a - b
print("Result of " + str(a) + " - " + str(b) + " = " + str(answer) + "\n")
def mul(a, b):
answer = a * b
print("Result of " + str(a) + " * " + str(b) + " = " + str(answer) + "\n")
def div(a, b):
answer = a / b
print("Result of " + str(a) + " / " + str(b) + " = " + str(answer) + "\n")
# test functions
# add(4, 3)
# sub(6, 1)
# mul(3, 3)
# div(8, 2)
while True:
# print("")
print("Basic Calculator")
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("Input first number: "))
b = int(input("Input second number: "))
add(a, b)
elif choice == "B" or choice == "b":
print("Subtraction")
a = int(input("Input first number: "))
b = int(input("Input second number: "))
sub(a, b)
elif choice == "C" or choice == "c":
print("Multiplication")
a = int(input("Input first number: "))
b = int(input("Input second number: "))
mul(a, b)
elif choice == "D" or choice == "d":
print("Division")
a = int(input("Input first number: "))
b = int(input("input second number: "))
div(a, b)
elif choice == "E" or choice == "e":
print("Program ended.")
quit()
else:
print("Invalid input, program ended.")
quit()