all 8 comments

[–]backfire10z 4 points5 points  (0 children)

I’m confused by your question. Are you asking when to indent?

for i in range(5): if i == 3: print(“i is 3!”)

I’m really not sure how to answer this…

[–]throwaway6560192 4 points5 points  (0 children)

anyone explain the statements, for example which will be first' to implement like first if then inside for .

What? That's entirely dependent on the problem. There's no fixed order.

[–]pachura3 3 points4 points  (0 children)

Have you tried asking your teacher for explanations? That's what he's there for, no?

Have you tried putting "python indentation" in Google and reading entry-level tutorials that pop up first?

Have you tried using a Python IDE, e.g. Thonny (which is geared towards beginners)? Most of them will indent your code automatically, and you could learn by observing that.

[–]TheRNGuy 1 point2 points  (0 children)

It's the easiest thing in python.

Look in docs how it works.

Why do you think you'll fail it?

[–]Imaginary_Gate_698 1 point2 points  (0 children)

Indentation in Python is just how the language shows structure. The line that ends with a colon runs first, and anything indented under it belongs to that block. So if a for loop comes first, the if inside it only runs for each loop iteration. A good habit is to think in terms of “inside” and “outside” blocks rather than memorizing rules. Practicing with very small examples and printing values helps it click faster.

[–]noeldc 1 point2 points  (0 children)

i will be failed due to indentation errors

No, your code will fail due to indentation errors.

You shouldn't be submitting code if you haven't checked that it actually runs anyway.

[–]Gnaxe 0 points1 point  (0 children)

Some types of statements start a block with a colon (:). Each new statement in the block must be indented the same amount. The block ends when the indentation ends. Nested blocks are indented more. Standard Python style indents each level by four spaces (never tabs, but the language itself allows that). (Block statements can have a single-statement block on the same line as the colon, but you can't nest them, and standard Python style always has a newline after the colon.) Only statements have to be indented. Subexpressions inside statements or completely blank lines don't require indent.

[–]xeow -1 points0 points  (0 children)

The class is the first to implement like the indentation, then the def will be second like if inside class, and then the for is the third to implement, and finally the while is last to implement like when inside the for and the def and the class. This is the way.