-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert^topow.py
More file actions
95 lines (95 loc) · 2.13 KB
/
convert^topow.py
File metadata and controls
95 lines (95 loc) · 2.13 KB
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
from math import sin, cos
str=raw_input("Enter the string\n")
def convert_to_pow(str):
(b1,b2)=str.split('^',1)
if b1[-1]!=')' and b2[0]!='(':
count=-1
c=''
for i in range(0,len(b1)):
if b1[count-i]=='+' or b1[count-i]=='-' or b1[count-i]=='*' or b1[count-i]=='/' or b1[count-i]=='^' or b1[count-i]=='(' or b1[count-i]==')':
break;
else:
c=b1[count-i]+c
d=''
for i in range(0,len(b2)):
if b2[i]=='+' or b2[i]=='-' or b2[i]=='*' or b2[i]=='/' or b2[i]=='^' or b2[i]=='w' or b2[i]=='(' or b2[i]==')':
break;
else:
d=d+b2[i]
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
if b1[-1]!=')' and b2[0]=='(':
count=-1
c=''
for i in range(0,len(b1)):
if b1[count-i]=='+' or b1[count-i]=='-' or b1[count-i]=='*' or b1[count-i]=='/' or b1[count-i]=='^' or b1[count-i]=='w' or b1[count-i]=='n':
break;
else:
c=b1[count-i]+c
d='('
i=1
level=1
while(level!=0):
if b2[i]=='(':
level=level+1
if b2[i]==')':
level=level-1
d=d+b2[i]
i=i+1
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
if b1[-1]==')' and b2[0]!='(':
c=')'
i=-2
level=1
while(level!=0):
if b1[i]==')':
level=level+1
if b1[i]=='(':
level=level-1
c=b1[i]+c
i=i-1
d=''
for i in range(0,len(b2)):
if b2[i]=='+' or b2[i]=='-' or b2[i]=='*' or b2[i]=='/' or b2[i]=='s' or b2[i]=='p' or b2[i]=='w':
break;
else:
d=d+b2[i]
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
if b1[-1]==')' and b2[0]=='(':
c=')'
count=-1
i=-2
level=1
while(level!=0):
if b1[i]==')':
level=level+1
if b1[i]=='(':
level=level-1
c=b1[i]+c
i=i-1
d='('
i=1
level=1
while(level!=0):
if b2[i]=='(':
level=level+1
if b2[i]==')':
level=level-1
d=d+b2[i]
i=i+1
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
for i in range(0, len(str)-2):
if '^' in str:
str=convert_to_pow(str)
print str