Chyba chodzi Tobie o eval()
# expression to be evaluated
user_expr = input("Enter an expression in terms of variable a: ")
# enter the value of variable
a = int(input("Enter the value of a: "))
# evaluate the expression
result = eval(user_expr)
# printing evaluated result
print("Result = {}".format(result))
on-line
Enter an expression in terms of variable a: a*(a-3)+a^2
Enter the value of a: 7
Result = 33