This topic is READ ONLY
thagley81 (4) [Avatar] Offline
#1
Hello,

I'm working through chapter 11 right now and was wondering if anyone could help me gain a more intuitive understanding of how the additional print commands insure that the star loops are displayed correctly.
thagley81 (4) [Avatar] Offline
#2
Re: Chapter 11
Just to expand on my previous post:


numBlocks = int(raw_input('How many blocks of stars do you want? '))
for block in range(1, numBlocks + 1):
for line in range(1, block * 2):
for star in range(1, (block + line) *2):
print '*',
print <-----
print <------
warren.sande (211) [Avatar] Offline
#3
Re: Chapter 11
It's not so obvious in this forum due to the fact that it strips whitespace, so we can't see the indenting, but...

The first 'print' you pointed to starts a new line of stars. (The comma at the end of the previous 'print' in the loop will keep printing stars on the same line).

The second 'print' you pointed to puts a blank line between the blocks of stars.


numBlocks = int(raw_input('How many blocks of stars do you want? '))
for block in range(1, numBlocks + 1):
for line in range(1, block * 2):
for star in range(1, (block + line) *2):
print '*', # print another star on the same line
print <----- # start a new line of stars
print <------ # start a new block of stars (insert a blank line)

Hope this helps.


Regards,
Warren Sande