Issue with pattern program using loops
<p>I'm writing a program that takes two inputs, number of lines and number of cheers as input. The number of lines is how many lines the user wants to print out and the number of cheers are in the format that 1 cheer is the word "GO" and two cheers are two "GO" s ...and their is the word "BUDDY" within two neighboring GO's. And each new line has to be indented 3 spaces more then the one before. And this is the program I've come up with:</p>

<pre><code>lines = input("Lines= ")
cheers = input("Cheers= ")
if cheers == 1:
    i = 1
    space = 0
    S = ""
    while i&lt;=lines:
        S=S+(" "*space)+"GO \n"
        i += 1
        space+=3
    print S
else:
    n = 1
    cheer1 = "GO BUDDY "
    cheer2 = "GO"
    space = 0
    while n&lt;= cheers:
        print (" "*space)+(cheer1*cheers)+cheer2
        space+=3
        n += 1
</code></pre>

<p>But the problem with this is that it doesn't print out the right number of GO's in the number of cheers. How can I modify my code to fix this problem? This is the output format I want to get :</p>

<p><a href="http://i.stack.imgur.com/7ynbB.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/7ynbB.jpg" alt="This is the format of the ouput I want to get"></a></p>

<p>Often in Python you don't need any loops</p>

<pre><code>lines = int(input('Lines= '))
cheers = int(input('Cheers= '))

line = ' BUDDY '.join(['GO']*cheers)
for i in range(cheers):
     print(' '*(i*3) + line)
</code></pre>

python python-2.7 design-patterns