Need help (Basic python)...what did I do wrong?

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Oct 28 10:56:33 CEST 2006


"frankie_85" <steveadi at gmail.com> writes:

> I just made a simple code which is part of my assignment

You may want to review the restrictions your educational institution
has on collusion.

> a function that takes one floating point number x as its argument
> and returns (the square root of the absolute value of x) plus (5
> times x cubed).
>
> and read 5 floating point values from the user into a list then
> apply the function to each value in the list and print the results
> in reverse order.
>
> --------------------------------------------------------------------------------------------
> import math
>
> print "Enter 5 values:"
> a = float(raw_input())
> b = float(raw_input())
> c = float(raw_input())
> d = float(raw_input())
> e = float(raw_input())

This reads five values, but assigns five separate names to them. You
will want to review your course notes on Python to find out what a
'list' is.

> it always gives me these error messages:
>
> Traceback (most recent call last):
>   File "/Users/x/Documents/test3.py", line 25, in <module>
>     funct(a, b, c, d, e)
>   File "/Users/x/Documents/test3.py", line 11, in funct
>     a_1 = math.sqrt(math.fabs(a)) + 5((math.pow(a,3)))
> TypeError: 'int' object is not callable
>
> What did I do wrong? Please help me

The error message is telling you that you have "called" an integer
('int') object. Integer objects don't support being called like
functions.

The syntax for "calling" an object is:

    foo(something, something_else)

Look at the line of code reported in the error, and you'll find an
integer object being called in that fashion. You'll need to rewrite it
so it does what you're actually trying to do.

Again, please make sure you work on these problems yourself; your
assessment should not be testing your ability to ask on the internet
for assistance.

-- 
 \       "All good things are cheap; all bad are very dear."  -- Henry |
  `\                                                     David Thoreau |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list