How to fix: "expected indented block" error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bryan Vargas
    New Member
    • Nov 2010
    • 1

    How to fix: "expected indented block" error

    I keep getting the same "expected indented block" when ever I run my code.

    Code:
    from myro import*
    
    init("simulator")
    
    def main():
        
    for x in range(10): #repeats code in loop 10 times
    
    forward(1,1) # go forward for a small distance
    
    backward(1,1) # go backwards the same distance as forward
    
    turnLeft(50,30) # slight turn to vacuum a new area 
    
    main()
    Last edited by bvdet; Nov 1 '10, 09:43 PM. Reason: Add code tags. Move title to message. Add appropriate title. Please use code tags when posting code. [code]....code goes here....[/code]
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You have no indentation in your code. Indentation is required to denote different blocks of code. The interpreter expects the indentation after certain statements and an IndentationErro r is raised if not present. Example:
    Code:
    >>> for i in range(10):
    ... print i
    Traceback (IndentationError: expected an indented block (<interactive input>, line 2)
    >>>

    Comment

    • Oralloy
      Recognized Expert Contributor
      • Jun 2010
      • 988

      #3
      You forgot to indent the statements wrapped in the "for" loop.

      Code:
      from myro import* 
      init("simulator") 
      def main(): 
      for x in range(10): #repeats code in loop 10 times 
        forward(1,1) # go forward for a small distance 
        backward(1,1) # go backwards the same distance as forward 
        turnLeft(50,30) # slight turn to vacuum a new area  
      main()

      Comment

      Working...