#๐ Can some one help to construct a pattern like this using nested for loop only?
24 messages ยท Page 1 of 1 (latest)
@reef thunder
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.
What have you tried so far?
for i in range(1,5):
for j in range(1,i+1):
print(j,end="")
print()
ahhh index of print-
now good
ok, now do you know how to reverse a range so it counts backwards instead?
yea
for i in range(5,0,-1)
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
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()
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.
the other loop shouldn't be nested again
you should have 3 loops. One outer loop, and then 2 inner loops
also give this embed a read
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.