File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ def add (a ,b ):
2+ return a + b
3+ def subtract (a ,b ):
4+ return a - b
5+ def multiply (a ,b ):
6+ return a * b
7+ def divide (a ,b ):
8+ return a / b
9+ operations_dict = {
10+ "+" : add ,
11+ "-" : subtract ,
12+ "*" : multiply ,
13+ "/" : divide
14+ }
15+ number1 = int (input ("enter first number: " ))
16+ for symbol in operations_dict :
17+ print (symbol )
18+ continue_flag = True
19+ while continue_flag :
20+ op_symbol = input ("Pick an operation:" )
21+ number2 = int (input ("enter next number:" ))
22+ calculator_function = operations_dict [op_symbol ]
23+ output = calculator_function (number1 ,number2 )
24+ print (f"{ number1 } { op_symbol } { number2 } ={ output } " )
25+
26+ should_continue = input (f"Enter 'y' to continue calculation with { output } or 'n' to exit" ).lower ()
27+ if should_continue == 'y' :
28+ number1 = output
29+ else :
30+ continue_flag = False
31+ print ("Bye" )
You can’t perform that action at this time.
0 commit comments