Python exercise

Asked

Viewed 228 times

3

In the codeacademy, I’m having the error with the following code:

# Tenha certeza que the_flying_circus() retorna True
def the_flying_circus():
    if  5==5 :    # Comece seu codigo aqui!
    return True
        # Nao esqueca de recuar
        # o codigo dentro deste bloco!
    elif 5!=5 or 6>=4 :
    return False
    else: 
    return False
        # Continue aqui.
        # Voce vai querer adicionar tambem a declarao else!

Error:

Your setbacks look a little strange. Read the Tip if you need to helping!

  • Somebody help me out??

  • That’s my favorite thing about Pyhton. It forces the guy to be organized :) pity that it still leaves to make code crude, redundant :( The Codeacademy teaches it? Good to know for me not to indicate.

1 answer

7

The indentation in Python must be respected so that the code is executed in perfect block.

Just add a tab or 4 espaços[1] on lines running within conditional structures:

def the_flying_circus():
    if  5==5:
        return True //identar
    elif 5!=5 or 6>=4:
        return False //identar
    else: 
        return False //identar

print the_flying_circus() //chamar função

I tested that code on it codeacademy and it worked. You can test the pythonfiddle also.

Indentation is a predominant feature in the language Python.

While code blocks are explicitly delimited in C, Java and PHP by keys, in Pascal and Fortran by keywords such as then and endif, in Python blocks are delimited by spaces or tabulations forming a visual indentation, there are no symbols(in fact, the symbols, are the tabulations themselves, or spaces) that indicate when the code of a given function starts, or ends.

For this reason python requires a standardized indentation. In other languages, such as C/C++ or JavaScript, indentation is not required due to block delimiters, being used only for better visualization.

  • do not recommend bad practices, suggest using 4 spaces and not tab for identation

  • @tovmeod, even if old, on this subject here in the OS: http://stackoverflow.com/questions/119562/tabs-versus-spaces-in-python-programming, other link: http://stackoverflow.com/questions/120926/why-does-python-pep-8strongly-recommend-spaces-over-tabs-for-indentation&#Xa

  • Like it or not, this is the standard adopted by the python community, it is wrong to teach rent by learning the way to do things differently than >90% does

Browser other questions tagged

You are not signed in. Login or sign up in order to post.