1 Replies - 1065 Views - Last Post: 12 June 2012 - 07:39 AM Rate Topic: -----

#1 dreamincodedot  Icon User is offline

  • New D.I.C Head

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

'for' loop pattern

Posted 12 June 2012 - 07:23 AM

Attached Image

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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1