Python Forum
I am a newbie.Please help me! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I am a newbie.Please help me! (/thread-26484.html)



I am a newbie.Please help me! - feynarun - May-03-2020

numbers = [2,2,5]

for x_count in numbers:
    output = ''
    for count in range(x_count):
        output += 'x'
        print(output)
I am trying to print an "L" shape using "x".ie, the First line will consist of two "x"'s. Second-line will consist of two "x"'s and the last line will consist of five "x"'s. I copied this exact code from a python video tutorial. But, The output does not look like "L" and it is something else altogether.

This is the output

Output:
x xx x xx x xx xxx xxxx xxxxx
Please tell me. Where did I go wrong?


RE: I am a newbie.Please help me! - buran - May-03-2020

the last line (#7) should be out of the second loop - move it one level to the left.

As an alternative
numbers = [2,2,5]
 
for x_count in numbers:
    output = 'x' * x_count
    print(output)



RE: I am a newbie.Please help me! - feynarun - May-03-2020

Thank you.