Python Forum
Understanding program blocks
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understanding program blocks
#1
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,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply
#2
I've been writing code sine 1968, and never worried about (or even considered) blocks
It just happens, like walking.
Reply
#3
(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,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  RSA Cipher with blocks Paragoon2 0 453 Nov-26-2023, 04:35 PM
Last Post: Paragoon2
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,802 Dec-12-2022, 08:22 PM
Last Post: jh67
  I need help understanding a program structure using classes CompleteNewb 21 5,863 Feb-24-2022, 07:15 PM
Last Post: deanhystad
  Am I a retard - else and finally blocks in a try statement RubenF85 6 2,513 Jan-12-2021, 05:56 PM
Last Post: bowlofred
  How to tabulate correctly repeated blocks? Xiesxes 4 2,874 Mar-21-2020, 04:57 PM
Last Post: Xiesxes
  try/except blocks newbieAuggie2019 11 4,744 Oct-05-2019, 05:55 PM
Last Post: newbieAuggie2019
  The Empty List Blocks Recursion leoahum 6 5,243 Mar-05-2019, 06:55 PM
Last Post: leoahum
  help with understanding a program prompt drasil 5 2,899 Feb-14-2019, 05:54 PM
Last Post: ichabod801
  I need help understanding how to use and run this program! Thanks in advance! tc1chosen 6 4,729 Sep-01-2017, 01:56 PM
Last Post: tc1chosen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020