-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day10 - Modern Calculator.py
65 lines (53 loc) · 2.2 KB
/
Day10 - Modern 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 4 11:28:07 2021
@author: datadevil
"""
logo = """
_____________________
| _________________ |
| | Pythonista 0. | | .----------------. .----------------. .----------------. .----------------.
| |_________________| | | .--------------. || .--------------. || .--------------. || .--------------. |
| ___ ___ ___ ___ | | | ______ | || | __ | || | _____ | || | ______ | |
| | 7 | 8 | 9 | | + | | | | .' ___ | | || | / \ | || | |_ _| | || | .' ___ | | |
| |___|___|___| |___| | | | / .' \_| | || | / /\ \ | || | | | | || | / .' \_| | |
| | 4 | 5 | 6 | | - | | | | | | | || | / ____ \ | || | | | _ | || | | | | |
| |___|___|___| |___| | | | \ `.___.'\ | || | _/ / \ \_ | || | _| |__/ | | || | \ `.___.'\ | |
| | 1 | 2 | 3 | | x | | | | `._____.' | || ||____| |____|| || | |________| | || | `._____.' | |
| |___|___|___| |___| | | | | || | | || | | || | | |
| | . | 0 | = | | / | | | '--------------' || '--------------' || '--------------' || '--------------' |
| |___|___|___| |___| | '----------------' '----------------' '----------------' '----------------'
|_____________________|
"""
print(logo)
def add(n1,n2):
return n1+n2
def sub(n1,n2):
return n1-n2
def mul(n1,n2):
return n1*n2
def div(n1,n2):
return n1/n2
def calculator():
num1 = float(input("Enter the first number : "))
operations = {"+":add, "-":sub,"*":mul,"/":div}
for keys in operations:
print(keys, end="\t")
print("\n")
should_continue = True
while should_continue:
oper_sym = input("Which operations do you want to perform? ")
if oper_sym in operations:
num2 = float(input("Enter the next number : "))
cal_fun = operations[oper_sym]
ans = cal_fun(num1,num2)
print(f"{num1} {oper_sym} {num2} is {ans}")
if input("Enter 'y' to continue with the {ans} or 'n' to start a new calculation : ") == 'y':
num1 = ans
else:
should_continue = False
calculator()
else:
print("Enter a valid operation")
calculator()