PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Takes any polynom function of 2nd degree as
#input and calculates it.
import re
import sys
#Method to analyze the function string and
#calculates in this order: Values of the
#separate pieces (what's next to the operands) then those values according to the
#operands given (either + or -)
def calculateFunction(func):
func_pieces = []
variable = getX(func)
func_edit = func.replace("x", "*" + variable)
getFunctionPieces(func_edit, func_pieces)
operands = [func_pieces[3], func_pieces[5]]
init_vals = []
getInitialValues(init_vals, func_pieces, variable)
result = calculateValues(init_vals, operands)
print("\n\n" + func + " = " + str(result))
#Method to break the given function up into
#"pieces" e.g. "f(x)", "=" and the operands
#are pieces
def getFunctionPieces(func, func_pieces):
piece = ""
for ind in range(len(func)):
if func[ind] != " ":
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run