The Big if()


#15

Thanks For The Help leonhard_wettengmx_n
!!!


#16

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

#17

@itsamartya,

After you defined your the_flying_circus() function.

You have to call the function....

the_flying_circus()

#18

Thanks a ton.. It worked .. Forgot to call the 'master' :smile: ..
@leonhard_wettengmx_n


#19

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


#20

@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


#22

a = raw_input ("enter your age")
def the_flying_circus():
    if (a >=17 and a <=80):
        print "Old enough to have a driving license"
    return True
if (a < 17):
        print "You're too young to have a license!"
    return True
elif (a > 80):
    print "You're too old to have a license - take the bus!"
else
    print "Happy Driving!"
    return True
the_flying_circus()

hi, I'm also trying to complete this exercise... with the code above I'm getting the following error:

  File "python", line 9
    return True
              ^
IndentationError: unindent does not match any outer indentation level

Can't figure out what's wrong... please help!

Thanks in advance.


#23

@systempro49675,
Try it with

def the_flying_circus():
    #asking the age as part of the function
    a = raw_input ("enter your age")

    if (a >=17 and a <=80):
        print "Old enough to have a driving license"
        return True
    elif (a < 17):
        print "You're too young to have a license!"
        #to young and still True ??
        return True
    elif (a > 80):
        print "You're too old to have a license - take the bus!"
        #no return ???
    else:
        print "Happy Driving!"
        return True
the_flying_circus()

In Python the indentation is very important !!!!

A so-called code-block should have the same indentation

Look at the code....
the IF statement

  • if condition:
    • #4 space indentation
    • which will be it's code-block

#24

Yoru code doesn't work plz help


#25

@byteace83915,
Forgot a colon-: after the ELSE

I updated my Post http://discuss.codecademy.com/t/the-big-if/14933/23?u=leonhard.wettengmx.n
and tested...

I am so sorry!!


#26

leonhard.wettengmx.n that's okay i understood my confulison........ :b


#27

Hi, I've been trying something similar, but receiving a different error, and wondering if it's something specific regarding the assignment, since the following code works in the labs:

def the_flying_circus():
    episode = int(raw_input("What episode are you looking for?"))
    if ((episode) <= 13) and ((episode) > 0):    
        print "Series 1 aired from 5 October 1969 to 11 January 1970."
    elif ((episode) <= 26) and ((episode) > 13):
        print "Series 2 aired from 15 September 1970 to 22 December 1970."
    elif ((episode) <= 39) and ((episode) > 26):
        print "Series 3 aired from 19 October 1972 to 18 January 1973."
    elif ((episode) <= 45) and ((episode) > 39):
        print "Series 4 aired from 31 October 1974 to 5 December 1974."
    else:
        print "Monty Python's Flying Circus aired 45 episodes from 1969-1974."
print the_flying_circus()

So this works in lab, but returns "ValueError: invalid literal for int() with base 10:" in the lesson.

When I submit code as follows, it doesn't function properly (only returns "else") but the assignment accepts it because it contains return True after every conditional.

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    episode = raw_input("What episode are you looking for?")
    if ((episode) <= 13) and ((episode) > 0):    
        print "Series 1 aired from 5 October 1969 to 11 January 1970."
        return True
    elif ((episode) <= 26) and ((episode) > 13):
        print "Series 2 aired from 15 September 1970 to 22 December 1970."
        return True
    elif ((episode) <= 39) and ((episode) > 26):
        print "Series 3 aired from 19 October 1972 to 18 January 1973."
        return True
    elif ((episode) <= 45) and ((episode) > 39):
        print "Series 4 aired from 31 October 1974 to 5 December 1974."
        return True
    else:
        print "Monty Python's Flying Circus aired 45 episodes from 1969-1974."
        return True
print the_flying_circus()

#28

def the_flying_circus():
    #asking the age as part of the function
    a = raw_input ("enter your age")

    if (a >=17 and a <=80):
        print "Old enough to have a license"
        return True
    elif (a <= 17):
        print "You're too young, wait a while!"
        return False
    elif (a >= 80):
        print "You're too old to have a license, take the bus!"
        return False
    else:
        print "Happy Driving!"
        return True
the_flying_circus()

@leonhard.wettengmx.n apologies it's taken me so long to reply to this post, thanks again for you help... however I can run this code now, however no matter what value i enter as the age it always returns "You're too old to have a licence, take the bus!"... the error i get is ("Oops, try again, the_flying_circus() should return True, instead it returned: False")... what's missing?


#29

@systempro49675,
Read the instructions and do exactly as asked.....


#30

Oops, try again. The following exception was raised when calling the_flying_circus(): SyntaxError: unexpected EOF while parsing (, line 0)...... help!!!!!!!!!!!!!!!!


#31

@jozi10,
Please give us the FULL code you are using...


#32

Make sure that the_flying_circus() returns True

def the_flying_circus():

     a = input("20 ")
     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 # Keep going here.
     elif(a < 18):
        print "age is too low"
     return True
       # You'll want to add the else statement, too!
       # You'll want to add the else statement, too!

#33

@jozi10,
You can only use a return statement in a function

a = input("20 ")
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 # Keep going here.
elif(a < 18):
  print "age is too low"
  #return True

#34

thanks so much! i appreciate


#35

Hi, what am I doing wrong here?