You will be given a polynomial expression in string form. The expression will contain any of the following operations, written using standard mathematical notation for a single variable, "x", as illustrated in the examples below:
Your task is to write a function that can evaluate such a polynomial for a given value of x. You will receive two arguments: the polynomial string and the input number.
If the mathematical expression contains an error, you should return "invalid".
evaluate_polynomial("x+1", 5) ➞ 6
evaluate_polynomial("5x^2", 3) ➞ 45
evaluate_polynomial("(x(x+1))/2", 4) ➞ 10
evaluate_polynomial("4(x + 3))/2", 5) ➞ "invalid"
# Invalid because parentheses not balanced.
The string will not contain spaces.