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
  link variable to exc blocks garbage collection Astrobert 1 651 Nov-19-2025, 05:03 AM
Last Post: Gribouillis
Photo Converting Pandas DataFrame to a table of hourly blocks Abedin 1 1,422 Apr-24-2025, 01:05 PM
Last Post: snippsat
  RSA Cipher with blocks Paragoon2 0 1,699 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 5,262 Dec-12-2022, 08:22 PM
Last Post: jh67
  I need help understanding a program structure using classes CompleteNewb 21 11,776 Feb-24-2022, 07:15 PM
Last Post: deanhystad
  Am I a retard - else and finally blocks in a try statement RubenF85 6 4,530 Jan-12-2021, 05:56 PM
Last Post: bowlofred
  How to tabulate correctly repeated blocks? Xiesxes 4 4,777 Mar-21-2020, 04:57 PM
Last Post: Xiesxes
  try/except blocks newbieAuggie2019 11 8,541 Oct-05-2019, 05:55 PM
Last Post: newbieAuggie2019
  The Empty List Blocks Recursion leoahum 6 8,509 Mar-05-2019, 06:55 PM
Last Post: leoahum
  help with understanding a program prompt drasil 5 4,710 Feb-14-2019, 05:54 PM
Last Post: ichabod801

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.