#๐Ÿ”’ Can some one help to construct a pattern like this using nested for loop only?

24 messages ยท Page 1 of 1 (latest)

reef thunder
#
      A
    B A B
  C B A B C
D C B A B C D
rich crestBOT
#

@reef thunder

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

Hey @reef thunder!

It looks like you incorrectly specified a language for your code block.

Make sure you put your code on a new line following py. There must not be any spaces after py.

Here is an example of how it should look:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
raw raptor
reef thunder
#

i didnt do, too hard to think

#

im trying to do

            1
          2 1 2
        3 2 1 2 3
      4 3 2 1 2 3 4 
raw raptor
#

Break it down into small steps. Focus on just this first

reef thunder
#
for i in range(1,5):
   for j in range(1,i+1):
     print(j,end="")
   print()
#

ahhh index of print-

#

now good

raw raptor
#

ok, now do you know how to reverse a range so it counts backwards instead?

reef thunder
#

for i in range(5,0,-1)

raw raptor
#

ok, so add that as another separate loop before your current one

#

also make sure you're using a variable instead of just 5

#

this should work for any number

reef thunder
#

n=5
for i in range(1,n+1):
space=(n-i)*" "
print(space,end="")
for j in range(i,1,-1):
print(j,end="")
for k in range(1,i+1):
print(k,end="")
print()

rich crestBOT
#

Hey @reef thunder!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
raw raptor
#

the other loop shouldn't be nested again

#

you should have 3 loops. One outer loop, and then 2 inner loops

raw raptor
rich crestBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.