By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

How to fix: "expected indented block" error

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

Expand|Select|Wrap|Line Numbers
  1. from myro import*
  3. init("simulator")
  5. def main():
  7. for x in range(10): #repeats code in loop 10 times
  9. forward(1,1) # go forward for a small distance
  11. backward(1,1) # go backwards the same distance as forward
  13. turnLeft(50,30) # slight turn to vacuum a new area 
  15. main()
Nov 1 '10 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 2.5K+
P: 2,851
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 IndentationError is raised if not present. Example:
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(10):
  2. ... print i
  3. Traceback (IndentationError: expected an indented block (<interactive input>, line 2)
  4. >>> 
Nov 1 '10 #2

Expert 100+
P: 983
You forgot to indent the statements wrapped in the "for" loop.

Expand|Select|Wrap|Line Numbers
  1. from myro import* 
  2. init("simulator") 
  3. def main(): 
  4. for x in range(10): #repeats code in loop 10 times 
  5.   forward(1,1) # go forward for a small distance 
  6.   backward(1,1) # go backwards the same distance as forward 
  7.   turnLeft(50,30) # slight turn to vacuum a new area  
  8. main() 
Nov 1 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.