Skip to content

Commit a110e7e

Browse files
committed
Day 10 - calculator function complete
1 parent 8050b40 commit a110e7e

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

Day_10/Calculator.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# TODO: Write out the math function - Add, subtract, multiply and divide.
2+
def add(n1, n2):
3+
return n1 + n2
4+
5+
def subtract(n1, n2):
6+
return n1 - n2
7+
8+
def multiply(n1, n2):
9+
return n1 * n2
10+
11+
def divide(n1, n2):
12+
return n1 / n2
13+
14+
# TODO: Add these function into a dictionary as the values. Keys = "+", "-", "*", "/"
15+
16+
operations = {
17+
"+": add,
18+
"-": subtract,
19+
"*": multiply,
20+
"/": divide
21+
}
22+
23+
#TODO: calculator_function
24+
def calculator():
25+
should_accumulate = True
26+
num1 = int(input("Enter first number: "))
27+
while should_accumulate:
28+
for operation in operations:
29+
print(operation)
30+
operation_symbol = input("Enter operation: ")
31+
num2 = int(input("Enter second number: "))
32+
answer = operations[operation_symbol](num1, num2)
33+
print(f"{num1} {operation_symbol} {num2} = {answer}")
34+
choice = input(f"Type 'y' to continue calculation with {answer}?, or type 'n' to start new calculation: ")
35+
if choice == "y":
36+
num1 = answer
37+
else:
38+
should_accumulate = False
39+
print("\n" * 20)
40+
calculator()
41+
42+
calculator()
43+
44+
45+
46+

Day_9/bidding.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
def find_highest_price(biding_dictionary):
42
winner = ""
53
highest_bid = 0

0 commit comments

Comments
 (0)