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

F

frankie_85

Hi everyone,

I just made a simple code which is part of my assignment but I can't
figure it out what's wrong with it. (always give me error messages)

What the code basically does is:

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())

def funct(a, b, c, d, e):
a_1 = math.sqrt(math.fabs(a)) + 5((math.pow(a,3)))
b_2 = math.sqrt(math.fabs(b)) + 5((math.pow(b,3)))
c_3 = math.sqrt(math.fabs(c)) + 5((math.pow(c,3)))
d_4 = math.sqrt(math.fabs(d)) + 5((math.pow(d,3)))
e_5 = math.sqrt(math.fabs(e)) + 5((math.pow(e,3)))
return a_1
return b_2
return c_3
return d_4
return e_5
print e_5, d_4, c_3, b_2, a_1



funct(a, b, c, d, e)


--------------------------------------------------------------------------------------------

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

Thanks in advance
 
L

Luuk

frankie_85 said:
Hi everyone,

I just made a simple code which is part of my assignment but I can't
figure it out what's wrong with it. (always give me error messages)

What the code basically does is:

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())

def funct(a, b, c, d, e):
a_1 = math.sqrt(math.fabs(a)) + 5((math.pow(a,3)))
b_2 = math.sqrt(math.fabs(b)) + 5((math.pow(b,3)))
c_3 = math.sqrt(math.fabs(c)) + 5((math.pow(c,3)))
d_4 = math.sqrt(math.fabs(d)) + 5((math.pow(d,3)))
e_5 = math.sqrt(math.fabs(e)) + 5((math.pow(e,3)))
return a_1
return b_2
return c_3
return d_4
return e_5
print e_5, d_4, c_3, b_2, a_1



funct(a, b, c, d, e)


--------------------------------------------------------------------------------------------

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

Thanks in advance


obviously the error is in the line "a_1 = math.sqrt(math.fabs(a)) +
5((math.pow(a,3)))"

try changin this to "a_1 = math.sqrt(math.fabs(a)) + 5*math.pow(a,3)"

because you seem to want 5 time the result of the pow() function
 
M

mensanator

frankie_85 said:
Hi everyone,

I just made a simple code which is part of my assignment but I can't
figure it out what's wrong with it. (always give me error messages)

What the code basically does is:

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())

def funct(a, b, c, d, e):
a_1 = math.sqrt(math.fabs(a)) + 5((math.pow(a,3)))
b_2 = math.sqrt(math.fabs(b)) + 5((math.pow(b,3)))
c_3 = math.sqrt(math.fabs(c)) + 5((math.pow(c,3)))
d_4 = math.sqrt(math.fabs(d)) + 5((math.pow(d,3)))
e_5 = math.sqrt(math.fabs(e)) + 5((math.pow(e,3)))
return a_1
return b_2
return c_3
return d_4
return e_5
print e_5, d_4, c_3, b_2, a_1



funct(a, b, c, d, e)


--------------------------------------------------------------------------------------------

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?

You forgot the *.
 
F

Fredrik Lundh

frankie_85 said:
a_1 = math.sqrt(math.fabs(a)) + 5((math.pow(a,3)))
TypeError: 'int' object is not callable

hint: in most programming languages, you have to use an explicit
operator to spell out multiplication. Python's no exception.

</F>
 
B

Ben Finney

frankie_85 said:
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.
 
S

Steven D'Aprano

frankie_85 said:
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. [snip]
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.

I don't think the restrictions against collusion are meant to prohibit
simple "what does this error message mean?" type questions. It would be
a funny sort of learning process that forced students to live in a
vacuum, never discussing their topic with anyone else, never asking the
most trivial questions.
 
J

James Stroud

Steven said:
frankie_85 said:
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. [snip]
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.

I don't think the restrictions against collusion are meant to prohibit
simple "what does this error message mean?" type questions. It would be
a funny sort of learning process that forced students to live in a
vacuum, never discussing their topic with anyone else, never asking the
most trivial questions.

I think you are wrong. The new trend is toward absolutely no instruction
at all and the students must guess the assignment. In this regard, I
believe the OP is doing very well. Don't you think?

James
 
A

Antoine De Groote

frankie_85 said:
Hi everyone,

I just made a simple code which is part of my assignment but I can't
figure it out what's wrong with it. (always give me error messages)

What the code basically does is:

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).

You also may want to review what (the) return (keyword) really means.
Hopefully this will point you to the other problem in your code. ;-)
 
F

frankie_85

Thanks for some of the helps guys.

Hmmm....after more trials and errors, I think what I did wrong is along
on these lines:

a_1 = math.sqrt(math.fabs(a)) + 5((math.pow(a,3)))
b_2 = math.sqrt(math.fabs(b)) + 5((math.pow(b,3)))
c_3 = math.sqrt(math.fabs(c)) + 5((math.pow(c,3)))
d_4 = math.sqrt(math.fabs(d)) + 5((math.pow(d,3)))
e_5 = math.sqrt(math.fabs(e)) + 5((math.pow(e,3)))

but I still don't understand though why the variable a, b, c, d, e
becomes an int type even though I have already specified the user input
to be floating point?

Once again thanks for all your help
 
P

Paul Rubin

frankie_85 said:
e_5 = math.sqrt(math.fabs(e)) + 5((math.pow(e,3)))

but I still don't understand though why the variable a, b, c, d, e
becomes an int type even though I have already specified the user input
to be floating point?

if you want to multiply two numbers you need to put a * between them.
* is the multiplication symbol in Python and most other languages.

When you say f(x) that says "there is a function x and Python should
call it on the value x". When you say 5(x), that says "there is
a function 5 and Python should call it with the value x". And then
when you try to actually do that, Python says "hey I can't do that,
5 isn't a function, it's an integer".
 
F

Fredrik Lundh

frankie_85 said:
Hmmm....after more trials and errors, I think what I did wrong is along
on these lines:

a_1 = math.sqrt(math.fabs(a)) + 5((math.pow(a,3)))
b_2 = math.sqrt(math.fabs(b)) + 5((math.pow(b,3)))
c_3 = math.sqrt(math.fabs(c)) + 5((math.pow(c,3)))
d_4 = math.sqrt(math.fabs(d)) + 5((math.pow(d,3)))
e_5 = math.sqrt(math.fabs(e)) + 5((math.pow(e,3)))

but I still don't understand though why the variable a, b, c, d, e
becomes an int type even though I have already specified the user input
to be floating point?

hint: besides the variables, what other values are involved in your
calculations? do you see any integers among them?

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top