The big if issue


#1



# Make sure that the_flying_circus() returns True
def the_flying_circus():
    a = raw.input ("enter your age")
    if (a >= 18 and a<=21):    # Start coding here!
        return True
    print "youre young af" 
        # Don't forget to indent
        # the code inside this block!
    elif (a >= 21):
        print "yeah youre old enough"
        return True 
        # Keep going here.
        # You'll want to add the else statement, too!
    elif (a >= 21):
        print "yeah youre too young"
        return true
    else:
        print "you have entered invalid text"
        return True

why doesnt my code work?
it says there is a syntax error on line 9


#2

elif can only follow immediately after if


#3

elif comes after an if. Correct the indentation here:

Take that in.

Also, you just had a repeat code here although printing different stuff. Err.. Correct that true to be True also.:

Hope this helps!? :smile:


#4

when you say elif comes after an if, what exactly does that mean?


#5

The indentation of the print statement before the first elif didn't make it see it so. Just correct the indentation like this:

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    a = raw.input ("enter your age")
    if (a >= 18 and a<=21):    # Start coding here!
        return True
    	print "youre young af" 
        # Don't forget to indent
        # the code inside this block!
    elif (a >= 21):
        print "yeah youre old enough"
        return True 
        # Keep going here.
        # You'll want to add the else statement, too!
    elif (a >= 21):
        print "yeah youre too young"
        return True
    else:
        print "you have entered invalid text"
        return True

#6

o ye ive done that, but then i recieve a "The following exception was raised when calling the_flying_circus(): NameError: global name 'raw' is not defined" in response and nothing appears


#7

Please paste your exact codes but before that refresh your browser and try again. Also indicate the error.

Thank you.


#8

Make sure that the_flying_circus() returns True

def the_flying_circus():raw
a = raw.input ("enter your age")
if (a >= 18 and a<=21): # Start coding here!
return True
print "youre young af"
# Don't forget to indent
# the code inside this block!
elif (a >= 21):
print "yeah youre old enough"
return True
# Keep going here.
# You'll want to add the else statement, too!
elif (a >= 21):
print "yeah youre too young"
return True
else:
print "you have entered invalid text"
return True

the error coming up is "Oops, try again. An exception was raised while running your code, see the console window for the error message."


#9

You're using the name raw which has not been defined.
Taking input from stdin also isn't something that this function should be doing. Your function should be equivalent to:

def the_flying_circus():
    return True

#10

thanks, so should i remove the raw from it and entirely change my code?


#11

Err... what's raw doing here?

Please see previous code and format as shown.


#12

a = raw.input ("enter your age")
if (a >= 18 and a<=21): # Start coding here!
return True
print "youre young af"
# Don't forget to indent
# the code inside this block!
elif (a >= 21):
print "yeah youre old enough"
return True
# Keep going here.
# You'll want to add the else statement, too!
elif (a >= 21):
print "yeah youre too young"
return True
else:
print "you have entered invalid text"
return True

ive formatted my code as this, but now it finds an error with my indenting at line 2


#13

Should you remove the use of something that doesn't exist? Probably. Or perhaps you should define it? Get a firm idea of what your function is supposed to do and go from there.

Whenever you feel like asking "Should ... ?" you can bounce that right back at yourself and consider what you intend to happen.


#14

alrighty thanks alot that makes sense


#15

I can't see your code formatting to know what went wrong. Select your code and use </> symbol so I could see.

Thank you.


#16

# Make sure that the_flying_circus() returns True
def the_flying_circus():
def raw.input()
a = raw.input ("enter your age")
if (a >= 18 and a<=21): # Start coding here!
return True
print "youre young af"
# Don't forget to indent
# the code inside this block!
elif (a >= 21):
print "yeah youre old enough"
return True
# Keep going here.
# You'll want to add the else statement, too!
elif (a >= 21):
print "yeah youre too young"
return True
else:
print "you have entered invalid text"
return True


#17

Here:

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    a = raw.input ("enter your age")
    if (a >= 18 and a<=21):    # Start coding here!
        return True
    	print "youre young af" 
        # Don't forget to indent
        # the code inside this block!
    elif (a >= 21):
        print "yeah youre old enough"
        return True 
        # Keep going here.
        # You'll want to add the else statement, too!
    elif (a >= 21):
        print "yeah youre too young"
        return True
    else:
        print "you have entered invalid text"
        return True

#18

thanks, but this results Oops, try again. The following exception was raised when calling the_flying_circus(): NameError: global name 'raw' is not defined


#19

I think @bayoishola20 means that any code you want others to look at better be intact.

As we've established, raw isn't defined. What you probably mean to use is raw_input, but that requests input through stdin and that's not something that your function should be doing.


#20

Okay, it should be:

a = raw_input("enter your age")

Where you ask the user to type in. It should be an underscore not a dot. Sorry for my error as well.

Please retry.