-
Notifications
You must be signed in to change notification settings - Fork 0
/
pycalc.py
145 lines (129 loc) · 4.05 KB
/
pycalc.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import sys
decore = "--------------------------------------"
qtxt = "\n\nThank you For Using Our Program\nExiting..."
pccv = "V2.0 build 021922"
reqtxt = "Do you want to do another operation (y/n/q): "
btc = "\nBack to the console\n"
badparam = "\nIncorrect parameter, back to console\n"
print(decore+"\nWelcome to PyCalc project: CLI Edition\n"+decore+"\nVersion: 7.0\n"+"Branch: Stable\n"+decore+"\nCopyright © 2022 TechVio\n"+decore+"\nLicensed under MIT license\n"+decore+"\nPyCalc console "+pccv+"\n"+decore)
def calcreq():
req = str.lower(input(reqtxt))
match req:
case 'y':
calc()
case 'n':
print(decore + btc + decore)
console()
case 'q':
print(qtxt)
sys.exit()
case _:
print(decore + badparam + decore)
console()
def mcalcreq():
req = str.lower(input(reqtxt))
match req:
case 'y':
mcalc()
case 'n':
print(decore+btc+decore)
console()
case 'q':
print(qtxt)
sys.exit()
case _:
print(decore+badparam+decore)
console()
def sqrtreq():
req = str.lower(input(reqtxt))
match req:
case 'y':
sqrt()
case 'n':
print(decore + btc + decore)
console()
case 'q':
print(qtxt)
sys.exit()
case _:
print(decore + badparam + decore)
console()
def calc():
print(decore)
n1 = float(input("Enter Your First Number: "))
print(decore)
op = input("Enter Your Operation: ")
print(decore)
n2 = float(input("Enter Your Second Number:"))
print(decore)
match op:
case "*":
result = float(n1*n2)
print(result)
calcreq()
case "+":
result = float(n1+n2)
print(result)
calcreq()
case "-":
result = float(n1-n2)
print(result)
calcreq()
case "/":
result = float(n1/n2)
print(result)
calcreq()
case "%":
result = float(n1 % n2)
print(result)
calcreq()
case "**":
result = float(n1**n2)
print(result)
calcreq()
case "//":
result = float(n1//n2)
print(result)
calcreq()
case _:
print("Error: Incorrect operation:"+"\nAddition : +"+"\nSubtraction : -"+"\nMultiplication: *"+"\nDivision : /"+"\nModulus : %"+"\nExponentiation: **"+"\nFloor division: //")
calc()
def sqrt():
from math import sqrt
print(decore)
num = float(input("Enter A Number: "))
print(decore)
result = sqrt(num)
print(result)
print(decore)
sqrtreq()
def mcalc():
calcul = input("Type calculation: ")
print(str(eval(calcul)))
print(decore)
mcalcreq()
def console():
calcmode = str.lower(input("Select Calculator Mode: "))
match calcmode:
case "help":
print(decore+'\nNormal calculator mode : "calc"'+'\nMulti-operations calculator mode: "mcalc"'+'\nsquare root mode : "sqrt"'+'\nConsole version : "version"'+'\nProject links : "projectlinks"\n'+decore)
console()
case "calc":
calc()
case "mcalc":
mcalc()
case "sqrt":
sqrt()
case "version":
print(pccv)
console()
case "exit":
print(qtxt)
sys.exit()
case "projectlinks":
print("Github: https://www.github.com/techvio1/PyCalc-Project/"+"\nGitLab: Working on final touches")
console()
case _:
print(decore+"\nIncorrect mode: Type 'help' for more informations\n"+decore)
console()
console()