#๐ help
105 messages ยท Page 1 of 1 (latest)
@twin dew
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.
i got the first 3 lines but not the bottom 2 lines
What's the code you have so far?
for i in range(0,3):
for j in range(i,3):
print("#",end="")
for k in range(0,2*i+1):
print("n",end="")
print()
Hey @twin dew!
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.
only the top 3 lines
!e
for i in range(0,3):
for j in range(i,3):
print("#",end="")
for k in range(0,2*i+1):
print("n",end="")
print()
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | ###n
002 | ##nnn
003 | #nnnnn
for i in range(0,3):
for j in range(i,3):
print("#",end="")
for k in range(0,2*i+1):
print("n",end="")
print()
the # is space
just for easier understanding
for i in range(0,3):
for j in range(i,3):
print(" ",end="")
for k in range(0,2*i+1):
print("n",end="")
print()
!e
code
what are you struggling with?
the bottom 2 lines
do you know about the range() function? do you know what parameters it can take?
i dont know how to make the loop for the last 2 lines
!d range
class range(stop)``````py
class range(start, stop[, step])```
The arguments to the range constructor must be integers (either built\-in [`int`](https://docs.python.org/3/library/functions.html#int) or any object that implements the [`__index__()`](https://docs.python.org/3/reference/datamodel.html#object.__index__) special method). If the *step* argument is omitted, it defaults to `1`. If the *start* argument is omitted, it defaults to `0`. If *step* is zero, [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) is raised.
For a positive *step*, the contents of a range `r` are determined by the formula `r[i] = start + step*i` where `i >= 0` and `r[i] < stop`.
For a negative *step*, the contents of the range are still determined by the formula `r[i] = start + step*i`, but the constraints are `i >= 0` and `r[i] > stop`.
are you familiar with the step parameter?
yeah, imagine you have a range from 1 to 10
but you want only odd numbers
so you would go every second number, skipping one
so you would have a step of 2
you would step 2 numbers at once
!e
print(list(range(1,10,2)))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
[1, 3, 5, 7, 9]
the first 2 parameters are start and stop
if stop is greater than start, then the step parameter can be negative
!e
print(list(range(10,1,-2)))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
[10, 8, 6, 4, 2]
so you can go the reverse order
do you understand?
for the next 2 lines, you just need a reverse for loop from the initial one
no problem, do you have any other questions?
yeah
tell me
I would do it in a tricky and hacky way
like write the output till 1, and store it as a string, and then reverse the string, remove the one, add both parts together and print it
print(*objects, sep=' ', end='\n', file=None, flush=False)```
Print *objects* to the text stream *file*, separated by *sep* and followed by *end*. *sep*, *end*, *file*, and *flush*, if present, must be given as keyword arguments.
All non\-keyword arguments are converted to strings like [`str()`](https://docs.python.org/3/library/stdtypes.html#str) does and written to the stream, separated by *sep* and followed by *end*. Both *sep* and *end* must be strings; they can also be `None`, which means to use the default values. If no *objects* are given, [`print()`](https://docs.python.org/3/library/functions.html#print) will just write *end*.
The *file* argument must be an object with a `write(string)` method; if it is not present or `None`, [`sys.stdout`](https://docs.python.org/3/library/sys.html#sys.stdout) will be used. Since printed arguments are converted to text strings, [`print()`](https://docs.python.org/3/library/functions.html#print) cannot be used with binary mode file objects. For these, use `file.write(...)` instead.
no
wait
yes
end=''
yeah
what about it
you can generate the first part with a for loop, print it, and the generate the other part (the other half of the row) with another for loop
and using the end="" parameter, will print the characters on the same row
@full prism can u call?
send the code as plain text
I am quite an introvert for that, and I usually find myself explaining better while writing, cuz I have more time to think and I sometimes make myself not understood because I am not a great speaker
for i in range(0,3):
for j in range(i,3):
print(" ",end="")
for k in range(0,2*i+1):
print("n",end="")
print()
for x in range(2,0,-1):
for y in range(x):
print(" ",end="")
for z in range(1,x):
print("n",end="")
print()
bruh
im an introvert too but its online
so i dont really care
but all good your wish
It seems like there aren't enough spaces, so I would increase the range for for x in range. 2 might be too low
it isnt working
ive tried everything
you're gonna print identical lines again. literally copy paste it ?
only difference is you do the lines in reverse order and don't repeat the middle
this is what im trying to make
yeah how do i do the last 2 lines
just copy paste the same code and reverse the loop
how do i reverse the loop
if you can count from 1 to 3 then surely you can count from 3 to 1
(2 to 1, since not including the middle)
i = 3
while i > 0:
i -= 1
I'm not saying that's what you should write, but I am saying that you should have no trouble doing it THAT way even if for some reason doing it with a for-loop is giving you trouble
ie. start at 3, and repeatedly subtract 1
also: you've already posted code that has a for-loop that counts down
though for some reason you changed the loop body in it even though the lines are identical and thus would use the same code as the first 3 lines
rows = 4
for i in range(rows):
for j in range(rows - i - 1):
print(" ", end="")
for k in range(2 * i + 1):
print("*", end="")
print()
for i in range(rows - 1):
for j in range(i + 1):
print(" ", end="")
for k in range(2 * (rows - i - 1) - 1):
print("*", end="")
print()
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.
๐ help