On Mon, Sep 28, 2015 at 1:27 PM, Ken Hammer <kfh...@earthlink.net> wrote: > 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? y = int(x) #see below
> > total = 0.0 > for i in range(len(poly)): > totalTerm = poly[i]* (x ** i) Here you would get "unsupported operand type" since you are getting the ith power of a string. > 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 > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor