The Big if()

Hi there, I am getting this error File “python”, line 12
elif (a > 21):
^
IndentationError: unindent does not match any outer indentation level while executing following code, can someone guide me?

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! 
  print "young, but not allowed to marry"
  return True
  

    # Don't forget to indent
    # the code inside this block!
elif (a >= 21):
  print "Yeah, you can marry"
  return True
elif(a < 18):
      print "age is too low"
      return True
else:
    print "somehing you entered which is not age"
    return True
    
    # Keep going here.
    # You'll want to add the else statement, too!
2 Likes

@shekhar2307,

In python the indentation is very important !!!

def the_flying_circus():
    #indent 4 spaces
    a = raw.input("enter your age ")
    if (a >= 18 and a <= 21): # Start coding here! 
        #indent 4 spaces, to indicate the IF code-block
        print "young, but not allowed to marry"
        return True    
        # Don't forget to indent
        # the code inside this block!
    elif (a >= 21):
        #indent 4 spaces, to indicate the ELIF code-block
        print "Yeah, you can marry"
        return True
    elif(a < 18):
        #indent 4 spaces, to indicate the ELIF code-block
        print "age is too low"
        return True
    # Keep going here.
    # You'll want to add the else statement, too!
    else:
        #indent 4 spaces, to indicate the ELSE code-block
        print "somehing you entered which is not age"
        return True
4 Likes

Thanks leonhard for help the code is working :smile:

leonhard_wettengmx_n
This is what I have so far: # Make sure that the_flying_circus() returns True
def the_flying_circus():
a = input(“Please Enter Your Age!”)
if (a >=18 and a <=21): # Start coding here!
print “Young, You Are Not Allowed To Marry!”
return True
# the code inside this block!
elif (a >=21):
print “You Are Allowed To Be Married!”
return True
# You’ll want to add the else statement, too!
elif (a < 18):
print “You Are Too Young To Be Married!”
return True

It doesn’t seem to be working. It comes up saying The following exception was raised when calling the_flying_circus(): SyntaxError: unexpected EOF while parsing (, line 0)

I’m Quite New To This So I Don’t Remember A lot! If You Could Help That Would Be Very Handy! Thanks, TeraNinja

@teraninja59169,
Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697

You need to add an else statement in your code than I think it should work fine.

Thank You

instead of raw.input, it should be raw_input, then the code will work on the console.
like this
def the_flying_circus(): #indent 4 spaces a = raw_input("enter your age ") if (a >= 18 and a <= 21): # Start coding here! #indent 4 spaces, to indicate the IF code-block print "young, but not allowed to marry" return True # Don't forget to indent # the code inside this block! elif (a >= 21): #indent 4 spaces, to indicate the ELIF code-block print "Yeah, you can marry" return True elif(a < 18): #indent 4 spaces, to indicate the ELIF code-block print "age is too low" return True # Keep going here. # You'll want to add the else statement, too! else: #indent 4 spaces, to indicate the ELSE code-block print "somehing you entered which is not age" return True
and leonhard’s code have helped me a lot, thank for that

3 Likes

@jrwang,
Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697

Make sure that the_flying_circus() returns True

def the_flying_circus():
x = raw_input(“enter a number!”)

if ( x <= 10 ):
    print ("Wow you must be 10 or less!")
    return True
elif ( x > 10 and x <= 20 ):
    print "Wow you must be between 10 and 20!"
    return True
elif ( x > 20 and x <= 30 ):
    print "Wow you must be between 20 and 30!"
    return True
else:
    print "You must be really old, you are older than 30"
    return True

Doesn’t work. I tried typing this in an got the error:

“File “python”, line 3
x = raw_input(“enter a number!”)
^
IndentationError: expected an indented block”

@hamish9,

def the_flying_circus():
    x = raw_input("enter a number!")
    if ( x <= 10 ):
         print ("Wow you must be 10 or less!")
         return True
    elif ( x > 10 and x <= 20 ):
         print "Wow you must be between 10 and 20!"
         return True
    elif ( x > 20 and x <= 30 ):
        print "Wow you must be between 20 and 30!"
        return True
    else:
        print "You must be really old, you are older than 30"
        return True
5 Likes

I’m incredibly confused. I’ve tried rewriting and copying/pasting your code here, as well as experimenting with my own and while I can pass the course, I can’t get anything to print to the console. Does anyone know why that might be?

@friedjohnnycake

Call the function to execute it in the console: the_flying_circus()
The raw_input appears to be considering the input as a string rather than an integer so no matter what number is inputted, it prints the else message. Wrap it with int()

x = int(raw_input("enter a number!"))
def the_flying_circus():
    if ( x <= 10 ):
         print ("Wow you must be 10 or less!")
         return True
    elif ( x > 10 and x <= 20 ):
         print "Wow you must be between 10 and 20!"
         return True
    elif ( x > 20 and x <= 30 ):
        print "Wow you must be between 20 and 30!"
        return True
    else:
        print "You must be really old, you are older than 30"
        return True
the_flying_circus()

I’m sorry, but I don’t get why you must type return True after every print statement. Thanks for any explanation.

1 Like

Thanks For The Help leonhard_wettengmx_n
!!!

Please Help… The program is passing me, but nothing coming in console where I Can Input my age

def the_flying_circus():
    result = raw_input("Enter Your Age!")
    if (result > 1 and result < 18):
        print "you are not allowed in the show"
        return True
    
    elif (result >= 19):
        print "Yes!! You are allowed to enter"
        return True
    
    else:
        print "Please enter your age properly"
        return True
1 Like

@itsamartya,

After you defined your the_flying_circus() function.

You have to call the function…

the_flying_circus()
1 Like

Thanks a ton… It worked … Forgot to call the ‘master’ :smile:
@leonhard_wettengmx_n

Make sure that the_flying_circus() returns True

def the_flying_circus():
a = raw_input(“whats your age”)
if (a >= 18 and a <= 21) :
print “young, you are not allowed to marry”
return True
#Dont forget to indent
# the code inside this block!
elif (a >= 21):
print " you are allowed to marry"
return True
# You’ll want to add the else statement, too!
elif (a < 18):
print " you are too young to be married"
return True
else:
print"something you entered is not related to age"
return True

This is my code but it shows an error as the following
File “python”, line 13
elif (a < 18):
^
SyntaxError: invalid syntax

@venkatb1umbc.edu,
You are not presenting the indentation you are using…
Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697/2
[extra’s]
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet