# 'for' loop pattern

Page 1 of 1

## 1 Replies - 1694 Views - Last Post: 12 June 2012 - 07:39 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=282545&amp;s=c894bcb8291781bcb913de6ad93d8716&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 dreamincodedot

• New D.I.C Head

Reputation: 0
• Posts: 2
• Joined: 12-June 12

# 'for' loop pattern

Posted 12 June 2012 - 07:23 AM

This is all that I've gotten so far..

for i in range (1, 10, 1):
print('#' * i)
for i in range (10, 0, -1):
print('#' * i)

I can't seeem to get the other side.
Is This A Good Question/Topic? 0

## Replies To: 'for' loop pattern

### #2 sepp2k

• D.I.C Lover

Reputation: 2277
• Posts: 3,507
• Joined: 21-June 11

## Re: 'for' loop pattern

Posted 12 June 2012 - 07:39 AM

There's two things, you need to realize:

1. For each line the number of #s on the left side is equal to the number of #s on the right side.
2. The number of #s on the left + the number of #s on the right + the number of spaces between them = the width of the shape (which from looking at the picture seems to be 12).

So if you know the width and you know how many #s you printed on the left side, you can calculate how many spaces to print before printing the right side.