I don't know why this is true


#1

Make sure that the_flying_circus() returns True

def the_flying_circus():
if 3<4: # Start coding here!
return True# Don't forget to indent
# the code inside this block!
elif 3<4 and 5>=10:
return False# Keep going here.
# You'll want to add the else statement, too!
else:
return True

The return in the box is "none"
I don't know what this code is supposed to do.
I don't see the results of this code
Can someone explain this to me?
Python is supposed to be the easiest code, but so far I've been stabbing blindly.


#2

If you would like to see the result of your code all you need to do is call and print your function,

print(the_flying_circus())


#3

How?
Like this?

Make sure that the_flying_circus() returns True

def the_flying_circus():
if 3<4: # Start coding here!
return True# Don't forget to indent
# the code inside this block!
elif 3<4 and 5>=10:
return False# Keep going here.
# You'll want to add the else statement, too!
else:
return False
print(the_flying_circus())
Or

Make sure that the_flying_circus() returns True

def the_flying_circus():
if 3<4: # Start coding here!
return True# Don't forget to indent
# the code inside this block!
elif 3<4 and 5>=10:
return False# Keep going here.
# You'll want to add the else statement, too!
else:
print(the_flying_circus())


#4

A function call needs to be outside of the functions indentation level and on its own line,

def the_flying_circus():
    if 3<4: # Start coding here!
        return True# Don't forget to indent
# the code inside this block!
    elif 3<4 and 5>=10:
        return False# Keep going here.
# You'll want to add the else statement, too!
    else:
        return True

print(the_flying_circus())

#5

Thanks.
I still don't understand what happened but something happened.
I mean,
if 3<4
return True.

'if' is a conditional statement, which means something must have happened for the RETURN to be true.
Sooooo, somewhere there must have been a result where 3<4.
Somewhere there must have been an INPUT where the result is 3<4.
But the code does not show me the INPUT of the result.

Same with print
if this_might_be_true():
print "This really is true."
elif that_might_be_true():
print "That is true."
else:
print "None of the above."

WHERE IS THE INPUT THAT CAUSES THINGS TO HAPPEN?


#6

Because your code is nested in a function, for the code inside your function to run it must be called and printed. :slight_smile:

Think about a function like a recyclable can but for you too see the contents of the can you have to open and in python you open a function by calling it.


#7

What?
I did not understand a single thing about your answer.


#8

Ok, let's make this a bit more practical,

def add(x, y):
    return x+y

the return statement in my function will not run until I call my add function,

add(23, 24)


#9

OK.
So you are creating a function where
x is added to y
and an answer shows up.
This is your code

Add (23, 24)
This is your input

yes?

I'm missing a key component here and I don't know what it is.
This is simple I know it is but I'm missing something.


#10

That function is adding both numbers together,

my function,

def add(x, y):
    return x+y
add(23, 24)  #its function call

Output: 47


#11

Ok I understand this.
You're telling the program that:
If a user takes 23 and adds 24
to show the answer of 47.
Yes?


#12

Yes, you can think about it like that. But that is not my point. My point is that the code inside a function will not run until the function is called.


#13

OK so Why did the box print True

def the_flying_circus():
if 3<4: # Start coding here!
return True
elif 3<4 and 5>=10:
return False
else:
return False

print(the_flying_circus())

Why didn't it print False?
Why didn't it print the_flying_circus?


#14

It returned True because your if condition evaluated True


#15

Sooo. Logically, if I wrote this
The box would print False?
because 3>4 is is incorrect mathematically?

def the_flying_circus():
if 3>4:
return True
elif 3<4 and 5>=10:
return False
else:
return False

print(the_flying_circus())


#16

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