-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (44 loc) · 1.48 KB
/
Copy pathmain.py
File metadata and controls
61 lines (44 loc) · 1.48 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
#Calculator
# add
from typing import final
from art import logo
def add (n1, n2):
return n1 + n2
#Subtract
def sub(n1, n2):
return n1 - n2
#Multiply
def mult(n1, n2):
return n1 * n2
#Divide
def div(n1, n2):
return n1 / n2
operations = {
"+": add,
"-": sub,
"*": mult,
"/": div,
}
def calculator():
print(logo)
num1 = float(input("What's the first number?: "))
for op in operations:
print(op)
operation_symbol = input("Pick an operation from the line above: ")
num2 = float(input("What's the second number?: "))
calculation_function = operations[operation_symbol]
first_answer = calculation_function(num1, num2)
print(f"{num1} {operation_symbol} {num2} = {first_answer}")
final_answer = first_answer
cont = input(f"Type 'y' to continue whith {final_answer}, type 'n' to start a new calculation or 'x' to exit: ")
while cont == "y":
operation_symbol = input("Pick another operation: ")
num3 = float(input("What's the next number?: "))
calculation_function = operations[operation_symbol]
second_answer = calculation_function(final_answer, num3)
print(f"{final_answer} {operation_symbol} {num3} = {second_answer}")
final_answer = second_answer
cont = input(f"Type 'y' to continue whith {final_answer}, type 'n' to start a new calculation or 'x' to exit: ")
if cont == "n":
calculator()
calculator()