Pyglatin 4/11


Hello All,

Please can somebody explain why the commands “if len…” and “else” only work if they have not been indented and why the “Print statements” require an indentation.
Example of a command that does work below.

Thank you in advance.



[print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input(“Enter a word:”)
if len(original) >5:
print original
print “less than 5”]



Any line that ends with a colon : tells the interpreter to expect a block, meaning the statement is not complete and there is a segment of code that must be executed given the correct condition.

if something:
    do something
    do something else

The indentation is very critical in Python since there are no block containers like in other languages such as C, Java and JavaScript.

if (something) {
    do something 
} else {
    do something else

In the above we don’t need to indent since the block is clealy delineated by the curly braces. Python does not have those so the indents are absolutely necessary and must be consistent.


thanks for your help MTF


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.