PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""**DAILY CHALLENGE**: Write a code that get as input a mathematical function as string. calculate and print the result of it!
form: f(3) = 2x^2 + 1x - 2
"""
def quad(func):
terms = func.split()
x = float(terms[0][2:-1])
a = float(terms[2][:-3])
b = float(terms[4][:-1])
c = float(terms[6])
if terms[3] == '-':
b *= -1
if terms[5] == '-':
c *= -1
return a*x**2 + b*x + c
"""test
print(quad("f(3) = 2x^2 + 1x - 2"
))
"""
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run