-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.py
42 lines (34 loc) · 959 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
import math
r=0
num1=float(input('enter the number1: '))
while True :
op=input('enter the op:+ , - ,* , /,^ ,sin , cos, tan , cot ,sqrt: ')
if op=='+'or op=='-' or op=='*' or op=='/' or op=='sin' or op=='cos ' or op=='sqrt' or op=='tan' or op=='cot' or op=='^':
break
else:
print('op is wrong')
if op=='+'or op=='-' or op=='*' or op=='/'or op=='^':
num2=float(input('enter the number2: '))
if op=='+':
r=num1+num2
elif op =='-':
r=num1-num2
elif op=='*':
r=num1*num2
elif op=='/':
r=num1/num2
elif op=='^':
r=num1**num2
print(str(num1)+op+ str(num2)+'='+str(r))
else:
if op=='sin':
r=math.sin(num1)
elif op =='cos':
r=math.cos(num1)
elif op=='tan':
r=math.tan(num1)
elif op=='cot':
r=1/math.tan(num1)
elif op=='sqrt':
r=math.sqrt(num1)
print(op+' '+ str(num1)+'='+str(r))