# For Loop in Python: Creating Symmetric Images

Page 1 of 1

## 1 Replies - 635 Views - Last Post: 24 November 2011 - 03:10 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=255515&amp;s=45471c9268af81d0e5ca1e8e8377191a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 collegecsstudent

Reputation: 0
• Posts: 2
• Joined: 13-November 11

# For Loop in Python: Creating Symmetric Images

Posted 13 November 2011 - 03:53 PM

I need help learning how to use a condition controlled or nested for loop to print the following outputin Python:

************************************
*** *** *** *** *** ***
*** *** *** *** *** ***
*** *** *** *** *** ***
*** *** *** *** *** ***
************************************

I know I need to use for loops so I was thinking:

```for i in range (0,1):
print ('*' * 36)
for i in range (2,4):
print ('***   ' *6)
for i in range (4,6):
print ('   ***' *6)
for i in range (6,7):
print ('*' * 36)

```

This generates the required output but is there a simpler way to do this with less code/fewer for statements? Help is appreciated thank you.

Required Output came out incorrectly. This is what it should be:

'*' * 36
'*** ' * 6
'*** ' * 6
' ***' * 6
' ***' * 6
'*' * 36

MOD EDIT: Fixed code tags. The proper way to use code tags:

This post has been edited by JackOfAllTrades: 13 November 2011 - 04:11 PM

Is This A Good Question/Topic? 0

## Replies To: For Loop in Python: Creating Symmetric Images

### #2 cupidvogel

Reputation: 31
• Posts: 593
• Joined: 25-November 10

## Re: For Loop in Python: Creating Symmetric Images

Posted 24 November 2011 - 03:10 AM

You can use a nested for loop to print out the inner 4 lines. This function would do it:

```def func():
print "* "*36
for i in range(4):
s = ""
for j in range(6):
s += "*** "
print s
print "* "*36

```

Just call func().