-coding utf-8- def functy ns ns print type O_o o_O spec tg sqrt sin co

 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
#-*-coding:utf-8-*-
def functy(ns,t):
s=ns
print s,type(s)#O_o o_O
spec=["tg","sqrt","sin","cos","ctg"]
if spec.index(t)==0:
return math.tan(float(s))
if spec.index(t)==1:
# print s
if float(s)>=0:
return math.sqrt(float(s))
else:
print "!"
raise ZeroDivisionError
if spec.index(t)==2:
return math.sin(float(s))
if spec.index(t)==3:
return math.cos(float(s))
if spec.index(t)==4:
return 1/math.tan(float(s))
def run(s):
spec=["tg","sqrt","sin","cos","ctg"]
i=0
while i<len(spec):
# print spec[i],s
sf=0
while sf!=-1:
nsf=s.find(spec[i],sf)
if nsf==-1:
break
sf=s.find("(",nsf)
n=0
j=sf+1
while j<len(s):
# print nsf,sf,j,n
if s[j]=="(":
n+=1
if s[j]==")":
if n==0:
# print s[sf:j+1]
s=s[:nsf]+"("+str(functy(run(s[sf:j+1]),s[nsf:sf]))+")"+s[j+1:]
break
n-=1
j+=1
i+=1
return compute(convert(s))