The Big if. The console return True but it isn't exactly as it wanted


#1



The Big if


I have a problem and it is that I have done the exercise in a way that the console return True but then appear me a message telling me:
Oops, try again. the_flying_circus should not take any arguments.


And in the console appear:
True
None
If you could help me I would appreciate it so much.

# Make sure that the_flying_circus() returns True
def the_flying_circus(answer):
    if answer== "Yes" :    # Start coding here!
        return True
        # the code inside this block!
    elif answer == "No" or not "Yes":
        return False
        # You'll want to add the else statement, too!
    else :
        return "Can you repeat it please?"

print the_flying_circus("Yes")


#2

here:

def the_flying_circus(answer):

the function should have no parameter, so remove answer

then also remove the argument from this line:

print the_flying_circus("Yes")

i know. it is not nice, but parameters and arguments are not allowed in this exercise


#3

Where else can you define variable besides calling a function and passing it as an argument?
Maybe you should define answer before the function, and set it equal to something that would make the_flying_circus return True.


#4

Hi, @lewis95 ,

(EDIT: Two other users beat me to it this time. :laughing: )
Take their advice. It is good.

The the_flying_circus function must not have any parameters, but you have this ...

def the_flying_circus(answer):

Revise it to work without the answer parameter.


#5

So generally we could say that it is correct, but not in this exercise.
And thank you so much.


#6

in general it would be good, but unfortunately the exercise won't allow parameters and arguments


#7

Ok, and thank you :slight_smile:


#8

Ok,
I am going to try it
And thank you course


#9

i was bored, i tried to cheat the exercise:

# Make sure that the_flying_circus() returns True
def the_flying_circus(*args):
    answer = args[0] if len(args) > 0 else "Yes"
    if answer== "Yes" :    # Start coding here!
        return True
        # the code inside this block!
    elif answer == "No" or not "Yes":
        return False
        # You'll want to add the else statement, too!
    else :
        return "Can you repeat it please?"

print the_flying_circus("Yes")

i used *args as parameter, this means that all additional arguments you supply at the function call are accessible in the function through args. args is a tuple (a immutable list), then inside the function i checked it any arguments are supplied, if so, use the argument else use "Yes"


#10

I have got it now

# Make sure that the_flying_circus() returns True
answer= "Yes"
def the_flying_circus():
    if answer== "Yes" :    # Start coding here!
        return True
        # the code inside this block!
    elif answer == "No" or not "Yes":
        return False
        # You'll want to add the else statement, too!
    else :
        return "Can you repeat it please?"

print the_flying_circus()

I put here to help other people.
I wish that this post it will be useful for other people


#11

@stetim94 ,

:sunglasses: Excellent :sunglasses:

This is my favorite exercise to hack.


#12

Is this not redundant?


#13

not "Yes" evaluates to False, so it is indeed unnecessary.

I think @stetim94 was trying to come up with a hack that was as close as possible to @lewis95 's original solution, but that the SCT would accept.


#14

it is redundant, but appylpye is right, i tried to get lewis95 code to work, allowing for parameters and arguments


#15

2 posts were split to a new topic: I don't understand what I'm doing wrong


#16

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