Hi all python programmers..I'm new to python and i'm having a doubt..
I'm running linux in my machine and i use "ipython" to run my python programs. I also write them in independent .py files..
But I'm not able to write loop-based programs in .py files, because after i save and run the program, the interpreter is showing an error "IndentationError: expected an indented block
"
I'm not able to write for loops as well...please help me out

thanks in advance :)

Member Avatar for iamthwee

Isn't whitespace important in python.

Check you have indented your code correctly.

Yes whitespace is part of the syntax. Make sure that you are indenting each block (anything that you would normally put between {} in C).

In Python, every WHITE SPACE costa an error.
So, check it once.
If you click enter after every statement, you should follow it.

In case of "if" and "else", you should follow "if" and then write "else" bottom to it.

Thats it.

here's some sample loops:

# For loop
temp = range(6)
for item in temp:
    print item

# While loop
i = 0
while i < 6:
    i += 1

Note the indentation. I'm using 4 spaces instead of a 'tab', as that's the preferred method of indentation (4 spaces) in Python.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.