-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.py
58 lines (45 loc) · 978 Bytes
/
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
#function to initiate calculation
def calculate():
print('''
use: ~ for square root
^ for square
+ for addition
- for subtraction
* for multiplication
/ for division
% for modulus
''')
#inputs by user
n1=float(input("n1:"))
op=input("op:")
if op == "~":
print(n1**0.5)
elif op == "^":
print(n1**2)
else:
n2=float(input("n2:"))
if op=="+":
print(n1+n2)
elif op=="-":
print(n1-n2)
elif op=="*":
print(n1*n2)
elif op=="/":
print(n1/n2)
elif op=="%":
print(n1%n2)
elif op=="_":
print((n1+n2)/2)
else:
print("invalid")
calculate()
#allow repeated calculations
print('''
Do u want to continue?
If Yes press 'Y'
If No press 'N'
''')
while input("Continue:").upper() == "Y":
calculate()
else:
print("End")