File tree 1 file changed +59
-0
lines changed
1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ def add (n1 , n2 ):
2
+ return n1 + n2
3
+
4
+ def subtract (n1 , n2 ):
5
+ return n1 - n2
6
+
7
+ def multiply (n1 , n2 ):
8
+ return n1 * n2
9
+
10
+ def divide (n1 , n2 ):
11
+ return n1 / n2
12
+
13
+ operations = {
14
+ "+" : add ,
15
+ "-" : subtract ,
16
+ "*" : multiply ,
17
+ "/" : divide
18
+ }
19
+
20
+ logo = '''
21
+ _____________________
22
+ | _________________ |
23
+ | | Lets Calculate | | .----------------. .----------------. .----------------. .----------------.
24
+ | |_________________| | | .--------------. || .--------------. || .--------------. || .--------------. |
25
+ | ___ ___ ___ ___ | | | ______ | || | __ | || | _____ | || | ______ | |
26
+ | | 7 | 8 | 9 | | + | | | | .' ___ | | || | / \ | || | |_ _| | || | .' ___ | | |
27
+ | |___|___|___| |___| | | | / .' \_| | || | / /\ \ | || | | | | || | / .' \_| | |
28
+ | | 4 | 5 | 6 | | - | | | | | | | || | / ____ \ | || | | | _ | || | | | | |
29
+ | |___|___|___| |___| | | | \ `.___.'\ | || | _/ / \ \_ | || | _| |__/ | | || | \ `.___.'\ | |
30
+ | | 1 | 2 | 3 | | x | | | | `._____.' | || ||____| |____|| || | |________| | || | `._____.' | |
31
+ | |___|___|___| |___| | | | | || | | || | | || | | |
32
+ | | . | 0 | = | | / | | | '--------------' || '--------------' || '--------------' || '--------------' |
33
+ | |___|___|___| |___| | '----------------' '----------------' '----------------' '----------------'
34
+ |_____________________|
35
+
36
+ '''
37
+ def calculator ():
38
+ print (logo )
39
+
40
+ num1 = float (input ("What's the first number?: " ))
41
+ for symbol in operations :
42
+ print (symbol )
43
+ should_continue = True
44
+
45
+ while should_continue :
46
+ operation_symbol = input ("Pick an operation: " )
47
+ num2 = float (input ("What's the next number?: " ))
48
+ calculation_function = operations [operation_symbol ]
49
+ answer = calculation_function (num1 , num2 )
50
+ print (f"{ num1 } { operation_symbol } { num2 } = { answer } " )
51
+
52
+ if input (f"Type 'y' to continue calculating with { answer } , or type 'n' to start a new calculation: " ) == 'y' :
53
+ num1 = answer
54
+ else :
55
+ should_continue = False
56
+ clear ()
57
+ calculator ()
58
+
59
+ calculator ()
You can’t perform that action at this time.
0 commit comments