Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import re
- def Trigonometry(text):
- operations=("^", '\u22c5', '\u22c5', '\u22c4', '\u2217', '\u2218', '\u2219', '\u22c7', "**")
- trig_funcs=['arcsin', 'arccos', 'arctg', 'arcctg', 'arctan', 'arcctan', 'sin', 'cos', 'tg', 'ctg', 'tan', 'ctan']
- result=''
- power=''
- arg=''
- argumen=''
- power_after_arg=False
- for one_fun in trig_funcs:
- if text.find(one_fun)!=-1:
- fun=one_fun
- text=text[len(fun):]
- break
- for i in operations:
- line=text.lower().replace(' ', '')
- if line.find(i)!=-1 and line[:text.find(i)]!='':
- power_after_arg=True
- # power = re.findall(r'\^\w*\d*', text)
- result = re.findall(r'\w+\d*', text)
- print(result)
- for i in range(len(result)):
- for j in result[i]:
- if i==0 and j in '1234567890qwertyuiopasdfghjklzxcvbnm+-' and power_after_arg==False:
- power+=j
- elif i==1 and j in '1234567890qwertyuiopasdfghjklzxcvbnm+-' and power_after_arg==True:
- power+=j
- elif j in '1234567890qwertyuiopasdfghjklzxcvbnm+-':
- arg+=j
- argumen=arg[:1]
- powerFul=power[:1]
- for i in power[1:]:
- if i in 'qwertyuiopasdfghjklzxcvbnm':
- powerFul+='*'+i
- else:
- powerFul+=i
- for i in arg[1:]:
- if i in 'qwertyuiopasdfghjklzxcvbnm':
- argumen+='*'+i
- else:
- argumen+=i
- if power=='':
- return (fun+'('+argumen+')')
- else:
- return (fun+'('+argumen+')**'+'('+powerFul+')')
- print(Trigonometry('cos^2 2x'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement