Ok, been a bit behind in updating on what I’m doing but first….rant.

I’m doing the Coursera python course and going through a quiz. I get this:

“Implement the mathematical function `f`(`x`) = -5 `x`^{5} + 69 `x`^{2} – 47 as a Python function. Then use Python to compute the function values `f`(0), `f`(1), `f`(2), and `f`(3). Enter the maximum of these four numbers.”

What the hell does f(x) mean??? I can’t find any documentation on what this ‘f’ is supposed to do to the “x”. I’m not a math major by any means but seriously….if you are going to put this into a quiz then have some damn resources so that we can find out what the hell this means…..

Math annoys me.

WordPress to the slight rescue. See, WordPress smartly suggest tags that may be appropriate to your topic based on words that you type. It caught “mathematical function” and suggested the Wikipedia article. I check it out and f(x) represents ‘function x’. Still don’t know what the hell that means.

Math annoys me.

Dammit!

So I try to write some code that turns this monstrosity into a program:

import math

# this is just my visual reference to the math equation

#f(x) = -5x**5 + 69x**2 – 47# assign the first f(o)

x = 0

a = (-5*(x**5)) + (69(x**2)) – 47print f(a)

And I get “TypeError: ‘number’ object is not callable”. OK fine….none of the documentation we have covers this…so off to Google.

No results found for

“TypeError: ‘number’ object is not callable”.

Oh this just keeps on getting better…..I’ve spent about 20mins on this one question……cover your eyes, I’m about to swear…

FUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUCK!!!!!!!!!!!!!!!!!

Sigh.

Update 2

Well got through it….even got 100 on the quiz on the first try too. I really don’t like learning such a hard way, no matter how well the lessons stick with you afterwards. 😦

## 9 Comments

Why, you were doing great.

You only had a typo-level mistake.

If you tried to run this code isolated you’d get a different error, saying there is no global name “f”. Can you see the error now?

But besides that, I very much recommend familiarizing yourself with the language of functions in mathematics, not for this question but because it’s very useful in life. The Wiki article seems a bit too information-intensive for an exposition.

Basically, a function takes things from one set to another set. Examples would be “from real numbers to real numbers” or “from coordinates on a chess board to (a chess piece name and color or “empty”)”. We usually denote functions f(x), g(x) h(z) and so on, but the important part is to have a name, then a “variable name” in parentheses.

Here are some example functions:

Our function, which we will call f, takes reals to reals, and is defined as:

f(x) = x * x

so for example, f(1) = 1 and f(2) = 4.

Our second function, which we will call first, takes words to letters, and specifically always takes a word to the first letter in the word, so for example:

first(“hello”) = ‘h’

first(“sonoflilit”) = ‘s’

This is very different from functions in python, but those get introduced in the course, I think, so I won’t say more about them.

The error “‘x’ is not callable” in python means you’re trying to put parentheses after something which isn’t a python function, e.g.

a = 5

b = a()

Thanks for your comment. I learned that it wasn’t so much that I was trying to call an ‘uncallable’, but more that I was just missing a * between the number and the bracket.

Then I finally figured out how to utilize ‘return’ in a def, which was the thing that was killing me. I could figure out the answer but couldn’t figure out how to get the answer to where it needed to be.

I was very tempted to call it quits. Learnpythonthehardway.org has a much better setup for learning python so far. RICE could take a SERIOUS lesson in ‘video classroom’ teaching from Khanacademy.org. I don’t know why they even bother putting links into their videos to open CodeSkulptor when you don’t really use it because you can’t see the video and use the other tab at the same time. And given that the video jut merely tells you things and you have the complete code in the tab just opened….it’s pointless.

Then you have a quiz with examples that are way out of any beginner’s league (without loosing soe hair in the process). Their course so far has a lot to be refined to be smooth.

This is why I’m a little saddened that Khan Academy can’t seem to get computer programming lessons right. Their math/science stuff is top notch…the rest….not so much.

See, this is why it annoys me so much that everytime an aspiring programmer asks if math is need, all the experienced programmers answer with “No”.

Well done though!

Thanks but yeah…’you don’t need to calculate it, just need to turn it into a program’ I got told….umm…duh. I always do my best to remember where I come from in all things…sure, I’m not perfect but hey, I don’t put down new people to things so badly. Luckily one person does not a chat-channel turn bad. Worse comes to worse, I’ll just block him 🙂

This learning material assumes (though they probably don’t remember to mention it) familiarity with high school math concepts and symbols (if not skill at applying them).

There are other learning materials meant to teach without assuming high school, and they are quite easy to find.

Math isn’t required to program (some things – in others math is essential, but that’s because the problem you’re trying to solve is mathematical in nature), but it’s a good example so many teaching materials meant for adults use it in examples.

I still stand by my comment and fully believe that by using the ‘high school math’ as a requirement automatically puts restrictions on who can take the course. If that is what they want, then it would be better worded “high school math from recent years’ If not, then at least point people in the direction of resources to help them complete the tasks. That is what I feel is reasonable. A wikipedia link is insufficient. A link to a Khan Academy video is good.

hahaha, I found a link to this page after getting the same error on the same question on the same quiz on the same Coursera class (only one week behind you)! And yes, I agree that the Week 1 quiz is overwhelming for a beginner and the instructors seem to go too fast and assume too much knowledge… these guys seem to have a classic geek lack-of-empathy problem. I’m actually good at math and understand the principles of what’s going on, but the syntax ain’t sticking, and when it doesn’t work it’s hard to figure out why. Such is the drawback of one-way classrooms.

Mind telling me what I’m doing wrong here?

def FinalAnswer(x):

FormulaAnswer = 5(x**5) + 69(x**2) – 47

return FormulaAnswer

V1 = FinalAnswer(0)

print V1

V1 = FinalAnswer(1)

print V1

V1 = FinalAnswer(2)

print V1

V1 = FinalAnswer(3)

print V1

This program works fine when I substitute a simpler formula into the second line (i.e. something like “x+5”), but as it stands, it makes Python choke and gives me the “TypeError: ‘number’ object is not callable” crap.

Argh nevermind, I finally got it. Didn’t realize you have to put a * between the 5 and x, and between the 69 and x, for them to multiply. It differs from normal algebra that way.

So this made it work:

def FinalAnswer(x):

….Formula = -5*(x**5) + 69*(x**2) – 47

….return Formula

V1 = FinalAnswer(0)

print V1

V2 = FinalAnswer(1)

print V2

V3 = FinalAnswer(2)

print V3

V4 = FinalAnswer(3)

print V4

Yeah…it’s always the stupid little things that mess you up…..sometimes it’s the lack of a proper example or definition