Python Forum
Understanding program blocks - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Understanding program blocks (/thread-21503.html)



Understanding program blocks - newbieAuggie2019 - Oct-02-2019

Hi!

Sorry for bothering you with this probably stupid question, but I can get really stuck with some little non-vital doubts.

If I understand program blocks correctly, the blocks have the same indentation level, inside a program, so if a program is just a list of print commands like:

print("Hello!")
print("This is a probably stupid question.")
print("Of course it is, you dimwit!")
I understand that this program consists of only one block of code.

Therefore, in a program like the following (I've used blank lines to better clarify which ones are the blocks with coloured rectangles):
[Image: program-blocks-02.png]

I think there are 4 code blocks:
1) The whole program, that I've named BLOCK A (the yellowish block).
2) The big pinkish block that I've named BLOCK B (that is inside BLOCK A).
3) The greenish block that I've named BLOCK C (that is inside BLOCK B, being this one also, inside BLOCK A).
4) The purplish block that I've named BLOCK D (that is inside BLOCK B, being this one also, inside BLOCK A).

But according to the book I saw it in, the author considers that there are only 3 blocks, the ones that I have coloured pinkish, greenish and purplish, and not considering the whole program as a bigger, outer block.

Am I wrong?

Sorry again for bothering you with this probably inconsequential question.

All the best,


RE: Understanding program blocks - Larz60+ - Oct-02-2019

I've been writing code sine 1968, and never worried about (or even considered) blocks
It just happens, like walking.


RE: Understanding program blocks - newbieAuggie2019 - Oct-02-2019

(Oct-02-2019, 06:10 PM)Larz60+ Wrote: I've been writing code sine 1968, and never worried about (or even considered) blocks
It just happens, like walking.

Wow! Coding must be for you like breathing!!!

This annoying and probably inconsequential doubt arose while trying to answer to the practice questions from the book and found out that the author probably had a different understanding of blocks than I do.

Oh, well ... Think

All the best,