"The Big If" -- Troubleshooting Code


#1

*Edit: For some reason the formatting is off...all code has correct indents. Can't seem to change this?

MY CODE:

def the_flying_circus(x):
if x <= 50:
return "This has potential"

elif x < 100 or x >= 105:
    return "This isn't working"

else:
    return "Try again"

print the_flying_circus(4)
print the_flying_circus(101)
print the_flying_circus(88)

ERROR MESSAGE:
Oops, try again. the_flying_circus should not take any arguments.

HELP?! :confused:


#2

Hi!

Your code is perfectly fine in practice - but not for this exercise.

The interpreter is not accepting your code because it is checking for a function that takes no parameters. Even though your code would run in another environment, the Codecademy interpreter looks to see if you followed their instructions.

So, try to modify your code to not include the variable x so the function can run with no parameters. You can simply modify your conditional statements and remove the x parameter from your def line, but remember, the_flying_circus() should return True in the end! :slight_smile:

Hope this helps!


#3

Off topic...

implies compiler error. The lesson checker examines code and outputs against the instructions. We typically refer to this as the SCT, Submission Correctness Test.

Check the spelling.


#4

Thanks! That's an important distinction..


#6

Hello, many thanks all! Had me scratching my head all of day last week!


#7

Hi @wowpalvabbit --

I tried your suggestion and it seems to work! But I do have one question -- in your post you mention that "it is checking for a function that takes no parameters."

Can you help me understand what is considered a "parameter?"

Many thanks!


#8

Hello again,

A parameter is simply a placeholder in a function definition that represents what will be passed to that function for use in the body of the function.

For example, say I wanted to create a function that calculates the price of an arbitrary used car. Some relative parameters might be year, condition, make, and model.

In our function definition, we would list these parameters because we expect the corresponding variables to be passed to the function when we call it later in the program. That would look like this:

def used_car_price(year, condiiton, make, model):
    year_value = 2016 - year
    if condition == "new":
        condition_value += 1000
    make_value = getMakeValue(make)
    model_value = getModelValue(model)
                               ...etc

This is just an example, but as you can see, the parameters in the function definition correspond to the variables we use inside the function. A call to the function would look like:

used_car_value(2009, new, BMW, 528i)

Where 2009, new, BMW, and 528i are our parameters.

Parameters are especially helpful when you consider the alternative of declaring several global variables, which can interfere with the rest of your program. Parameters are temporary and are only in the scope of the function they belong to.

Hope this helps!


#9

Very much, thank you :slight_smile:


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.