[Tutor] Python type confusion?
Ken Hammer
kfh777 at earthlink.net
Mon Sep 28 22:27:19 CEST 2015
A simple "type" problem?
The following code works as a py file with the XX'd lines replacing the two later "raw_input" lines.
Why do the "raw_input" lines yield a TypeError: 'str' object is not callable? Same result if I use/omit
the parens around the poly tuple.
#### evaluate a polynomial as formula for a defined function
##poly = (0.0, 0.0, 5.0, 9.3, 7.0) # f(x) = 7x^4 + 9.3x^3 + 5x^2
##x = -13
poly = raw_input("Type, 0.0-n ,") ## these do not work in place of above
x = raw_input("Type your val of x, ") ## 'str' object is not callable?
total = 0.0
for i in range(len(poly)):
totalTerm = poly[i]* (x ** i)
total += totalTerm
print "totalTerm ", i , totalTerm
print "Equation Value", total
#### Good answer follows:
totalTerm 0 0.0
totalTerm 1 0.0
totalTerm 2 845.0
totalTerm 3 -20432.1
totalTerm 4 199927.0
Equation Value 180339.9
>>>
thanks, Ken Hammer
More information about the Tutor
mailing list