I got stuck, please help me


#1



def the_flying_circus(answer):
    if answer<5:
        print "True"
        
    elif 5==5 and 7==8:
        print "False"# Keep going here.
    else:
         print "suck it" 

Some people tried to explain me but i don`t get it with technical words, please change what`s wrong so i can understand


#2

What are you stuck with? Are you getting an error or just don't understand what to do? Which lesson is this (providing a link to the lesson would be massively helpful)?


#3

It has to return "true"


#4

Can you provide me with a link to the exercise so I can see what it is they're asking for?


#5

Instructions
Write an if statement in the_flying_circus(). It must include:

if, elif, and else statements;
At least one of and, or, or not;
A comparator (==, !=, <, <=, >, or >=);
Finally, the_flying_circus() must return True when evaluated.
Don't forget to include a : after your if statements!


#6

Okay, going through your instructions, I can see where you've gone wrong:

Finally, the_flying_circus() must return True when evaluated.

This last step is tripping you up, as you've mixed up print and return statements.

The print statement (as you may have guessed) prints a variable to the console.

The return statement, on the other hand, sends an output to the program that called the function - for example:

def multiply_by_two(number):
    return number * 2

answer = multiply_by_two(10)
print answer # this would print "20" to the console

In this case, the function multiply_by_two() takes an input (the number 10), multiplies it by two, and returns it as an output for the program to use - in this example, storing the number in the answer variable.

Print is a command used simply to allow us, as humans, to SEE the output/value of a particular function or variable, but otherwise does nothing else.

EDIT: I should also point out that the lesson is asking you to return True (the boolean value) as opposed to "True" (the string).


#7

I can`t do it please write the code, i´ve tried to do it all day
def the_flying_circus(answer):
return answer+1

if answer<5:
    print 5==5 and 7==7

elif 5<answer:
    print 5==5 and 5==6# Keep going here.
else:
     print "suck it"

That´s the final code i did


#8

def the_flying_circus():
    return 5==5 and 5==5
    
    if answer<5:
        print 5==5 and 7==7
        
    elif 5<answer:
        print 5==5 and 5==6# Keep going here.
    else:
         print "suck it"

i did it! Even though i dont understand why it´s correct, it seems like the function isn´t doing nothing but evaluated true and, in other hand, the if/ else statement it´s trying to analyse something that is not typed


#9

The reason it worked is because of the first line of your function.

A comparison (for example, 5 == 5) will always be evaluated as True or False. So if you use return 5 == 5, the function would return True because the statement that 5 == 5 is true.

Equally, if you had typed return 5 == 6, the function would have returned False.

The reason none of the rest of the code executes is because a return statement ends the function (that's why they should be placed in a conditional, like an if statement).

Here's an example:

def my_function(number):
    if number < 10:
        return True # this ends the function
    else:
        return False # this also ends the function

my_function(5) # this would return True
my_function(9) # this would return True
my_function(11) # this would return False

I hope this clears things up a bit for you!


#10

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