-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_Calculator.py
71 lines (56 loc) · 2.45 KB
/
10_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
65
66
67
68
69
70
71
logo = """
_____________________
| _________________ |
| | Pythonista 0. | | .----------------. .----------------. .----------------. .----------------.
| |_________________| | | .--------------. || .--------------. || .--------------. || .--------------. |
| ___ ___ ___ ___ | | | ______ | || | __ | || | _____ | || | ______ | |
| | 7 | 8 | 9 | | + | | | | .' ___ | | || | / \ | || | |_ _| | || | .' ___ | | |
| |___|___|___| |___| | | | / .' \_| | || | / /\ \ | || | | | | || | / .' \_| | |
| | 4 | 5 | 6 | | - | | | | | | | || | / ____ \ | || | | | _ | || | | | | |
| |___|___|___| |___| | | | \ `.___.'\ | || | _/ / \ \_ | || | _| |__/ | | || | \ `.___.'\ | |
| | 1 | 2 | 3 | | x | | | | `._____.' | || ||____| |____|| || | |________| | || | `._____.' | |
| |___|___|___| |___| | | | | || | | || | | || | | |
| | . | 0 | = | | / | | | '--------------' || '--------------' || '--------------' || '--------------' |
| |___|___|___| |___| | '----------------' '----------------' '----------------' '----------------'
|_____________________|
"""
def addition(first, second):
print(f"{first} + {second} = {first+second}")
return first + second
def substraction(first, second):
print(f"{first} - {second} = {first-second}")
return first - second
def multiplication(first, second):
print(f"{first} * {second} = {first*second}")
return first * second
def divide(first, second):
print(f"{first} / {second} = {first/second}")
return first / second
operations = {
"+": addition,
"-": substraction,
"*": multiplication,
"/": divide
}
def calculator():
print(logo)
# user enters first number
num1 = float(input("What is your first number? "))
for symbol in operations:
print(symbol)
done = False
while not done:
# user chooses symbol
symbol = input("\nPick an operation from above: ")
# user enters second number
num2 = float(input("\nWhat is the second number? "))
op_function = operations[symbol]
answer = op_function(num1, num2)
if input(
f"\nEnter 'y' if you wish to continue using {answer} or 'n' if you wish to start again: "
) == "y":
num1 = answer
else:
done = True
calculator()
calculator()