The Big if()

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.

@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
1 Like

Yoru code doesn’t work plz help

@byteace83915,
Forgot a colon-: after the ELSE

I updated my Post The Big if()
and tested…

I am so sorry!!

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

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()
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?

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

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

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

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!

@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

thanks so much! i appreciate

Hi, what am I doing wrong here?

@dataninja04178,
The Oops-message (generated by the code-checker)
Oops, try again, the_flying_circus should not take any arguments.
( thus in the definition the_flying_circus() function does not take a PARAMETER )
( read the Function Talk in a separate Post )

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

def the_flying_circus():
    #4-space indent to indicate the FUNCTION code-block
  1. if, elif, and else statements;
def the_flying_circus():
    #4-space indent to indicate the FUNCTION code-block
    if condition1:
        # here the IF code-block
    elif condition2:
        # here the ELIF code-block
    else:
        # here the ELSE code-block
  1. At least one of and, or, or not;
  2. A comparator (==, !=, <, <=, >, or >=);
  • condition1::
    1 < 2 and 5 > 3
    gives a True

  • condition2::
    12%3 == 0 or 4*2>7
    gives a True


-04. Finally, the_flying_circus() must return True when evaluated.

def the_flying_circus():
    #4-space indent to indicate the FUNCTION code-block
    if condition1:
        # here the IF code-block
        return True
    elif condition2:
        # here the ELIF code-block
        return True
    else:
        # here the ELSE code-block
        return True

@dataninja04178,

the FUNCTION talk

def myFunc( param1, param2):
    # Begin of =myFunc= FUNCTION-BODY
    # this =myFunc= function- has 2 PARAMETERS param1 and param2
    # param1 and param2 PARAMETERS are used 
    # as -local- VARIABLES throughout the =myFunc= FUNCTION-BODY
    print( param1 + " and " + param2 )
    #End of =myFunc= FUNCTION-BODY

If you want to call/execute the myFunc function
you will have to add a pair of parentheses to myFunc
like
myFunc()
As the myFunc function was defined
as having 2 parameters
you have to provide 2 arguments
in our case 2 string VALUES “Alena” and “Lauren”
like
myFunc(“Alena”,“Lauren”)

some quotes from the outer-world:

argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block

OR

"parameters" are called “formal parameters”,
while “arguments” are called “actual parameters”.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++ function with 1 parameter using return-statement

def myFunction( param1 ):
    # //Begin of =myFunction= FUNCTION-BODY
    # //=myFunction= function has 1 PARAMETER param1
    # //this param1 PARAMETER is used as a -local- VARIABLE
    # //throughout the =myFunction= FUNCTION-BODY
    return param1;
    # //End of FUNCTION-BODY

You have defined a myFunction function
which takes 1 parameter param1
this param1 parameter is used
as a variable throughout the =myFunction= FUNCTION-BODY.

If you want to call/execute this myFunction function
and this myFunction function was defined
as having 1 parameter param1
you will have to provide 1 argument
in our case a “number VALUE” 4
myFunction( 4 )

some quotes from the outer-world:

argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block

OR

"parameters" are called “formal parameters”,
while “arguments” are called “actual parameters”.

============================================

As you are using the return-statement in your myFunction function
you will only get a return-value no-display.
You can however capture this return-value in a variable
and then use the print-method to do a display.

theResult = myFunction( 4 )
print theResult

OR directly

print myFunction( 4 )

hello I followed your sample but still not passed,
could you help me figure it our?

The following exception was raised when calling the_flying_circus(): NameError: global name ‘raw’ is not defined
and I do have indents but not showed I don’t know why.

Make sure that the_flying_circus() returns True

def the_flying_circus():
a = raw.data("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 “yes,you can marry”
return True
# Keep going here
# You’ll want to add the else statement, too!
elif (a<18):
print “age is too low”
return True
else:
print “something you entered which is not age”
return True

thank you so much!

@wererwefv,
You will have to change your

raw.data

into

raw_input

thanks

I already tried raw_date but still not pass:
The following exception was raised when calling the_flying_circus(): NameError: global name ‘raw_data’ is not defined

@wererwefv
#raw_input !!!