#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2016
    Posts
    4
    Rep Power
    0

    Unhappy Why does this code fail?


    Hi I am a newbie to Python. I have experience with other programming languages, but this is the first time I am taking a plunge in Python. Can anyone help me on why this code fails?

    Code:
    word=raw_input("Enter a word : ")
    if len(word)>0:
    	#code here for  true logic
    else:
    	#code here for false logic
    This is the error it throws back
    Code:
      File "ThisCodeWillFail.py", line 4
        else:
           ^
    IndentationError: expected an indented block
    If I remove the comment and place an executable statement it works.

    Thank you again for taking time for reading my post.

    ~ gocool
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,705
    Rep Power
    507
    Certainly you understand indentation as syntax in python. Comments are really ignored. Here are some alternatives:
    Code:
    if condition:
        '' #true logic   '' is my favorite place holder statement
    elif c2:
        pass # another case
    else:
        1 # finally!

    Comments on this post

    • gocool agrees : Thank you. Much appreciated.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo