Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def main():
- #userinput = input("Enter equation")
- global userinput
- userinput = 'x^2-3x+4'
- getValues(userinput)
- def getValues(userinput):
- try:
- x2 = list(re.findall(r'([-+]*)\s?(\d*)\s?(\w*)\s?\^\s?(\d*)',userinput)[0])
- x = list(re.findall(r'(?<!\^)([+-]*)\s?(\d*)\s?(\w*)\s?[-+]',userinput)[0])
- except IndexError:
- print('Check your equation. You messed up bigtime.')
- try:
- const = list(re.findall(r'([-+]*)(?<![\w])\s?(\d*)(?![-+\w])',userinput)[0])
- except IndexError:
- const = ['+','0']
- if x2[0] == '':
- x2[0] = '+'
- if x[0] == '':
- x[0] = '+'
- if const[0] == '':
- const[0] = '+'
- if x2[1] == '':
- x2[1] = '1'
- if x[1] == '':
- x[1] = '1'
- if const[1] == '':
- const[1] = '0'
- print("""x^2:
- Sign:{}
- Coefficient:{}
- Variable:{}
- Index:{}""".format(x2[0],x2[1],x2[2],x2[3]))
- print()
- print("""x:
- Sign:{}
- Coefficient:{}
- Variable:{}""".format(x[0],x[1],x[2]))
- print()
- print("""Constant:
- Sign:{}
- Constant:{}""".format(const[0],const[1]))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement