Difficulty with the Big If


#1

Here is my code:

# Make sure that the_flying_circus() returns True
def the_flying_circus(answer):
    if answer == 3:    # Start coding here!
        print True 
    elif answer >= 3 and not answer > 7:
        print True 
    else: 
        print False 
    the_flying_circus(2)
    the_flying_circus(5)

I am getting an error message that is telling me that the_flying_circus() variable should take no arguments. How do I proceed from here?


#2

You function takes an argument called answers:

def the_flying_circus(answer):

which is what trips the error, i would remove answer:

def the_flying_circus():

then inside the function, declare a variable answer and assign it a value:

def the_flying_circus():
    answer = 20432
    #rest of your function

you can call a function, from inside a function, but i wouldn't do that it in this case, it will create something called a recursive function call, sort of like an infinity loop, call the function outside the function, without any arguments:

def the_flying_circus():
    answer = 20432
    #rest of your function

the_flying_circus()

#3

Thank you for your thorough help.


#4

Here is how I followed up with your advice:

Why do I still get the error?


#5

my apologizes, i missed something. You use print True and print False, this should be return True (and obviously return False too). Also, on line 14 i would make a function call, make sure the indent is the same as the function, as i showed you in my first answer


#6

Hello again stetim94,
I changed my print commands to return and I attempted to add a "function call" on the last lines of the code. I looked back at your first reply to my question to try and get a better idea of what a function call would look like. I am guessing that in my first example, by putting answer in parentheses, I created what you called the "recursive function" call. Is this correct?

In any case, despite my latest efforts at correction, I am still getting an error message. Here is what my code looks like.


#7

The great thing about functions is that you can re-use them, so the moment you define a function:

def the_flying_circus():
    if answer > 5 and answer <=7:
        return True
    elif answer == 5:
        return True
    else:
        return False

it won't execute. It is just a block of code, the moment you add a function call, the function get's executed:

def the_flying_circus():
    if answer > 5 and answer <=7:
        return True
    elif answer == 5:
        return True
    else:
        return False

the_flying_circus() #function call

the function gets executed (note the indent, the function call is outside the function). Now, normally i would agree with you it would be good to pass a argument in this function, but then you can't pass the exercise. But we can also declare a variable inside the function:

def the_flying_circus():
    answer = 5
    if answer > 5 and answer <=7:
        return True
    elif answer == 5:
        return True
    else:
        return False

the_flying_circus()

#8

Thank you for your help!