#π Understanding issue
204 messages Β· Page 1 of 1 (latest)
@carmine dove
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.
what is it you don't understand?
Can you paste the code here as text please?
!code
the whole logic
ok
n = int(input("Enter the number :"))
for i in range (1, n+1):
print(" "* (n-i), end="")
print("" (2*i-1), end="")
print("")
Hey @carmine dove!
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.
Is there anything here you do understand?
nope
do you understand the input()?
yes
do you understand the int()?
yes
So you do understand something
do you understand what a for loop does?
do you understand how to for loop?
yes but
Yes
ok so what part of it don't you understand?
the part after first line
do you understand what range() is?
range print numbers right?
it doesn't print them
no
it simply creates a sequence of numbers
sequence, ok.
range(5) is basically the same as 0, 1, 2, 3, 4
yes
ik this
if i write range(0,5,2) : it will give sequence from 0 to 5 with 2 number space
ik range
yes
ok so we still don't know what you don't know then
sorry for saying idk but ye i remember now
That how the code works
code works by running each line
like n = int(input("Enter the number :"))
for i in range (1, n+1):
print(" " (n-i), end="")
print("" (2*i-1), end="")
print("")*
so do you understand what i represents in the for loop?
This line
that's not a line, that's the entire code
variable?|
yep pretty much exactly
yes its a variable and it holds the value from the iterable list range()
yeah
And after each iteration, it goes to the next value
wdym yeah?
!e
for i in range(5):
print(i)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 0
002 | 1
003 | 2
004 | 3
005 | 4
but idk what's goin on in the code, man
but you understand each component of it?
But do you understand what i is now?
like range, i, for,int,input, right?
yes i do
do you understand that you can multiply strings?
!e
for i in range(1, 6):
print('*' * i)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | *
002 | **
003 | ***
004 | ****
005 | *****
!e
print("hello"*3)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
hellohellohello
bruh
n = int(input("Enter the number :"))
for i in range (1, n+1):
print(" " (n-i), end="")
print("" (2*i-1), end="")
print("")*
Still don't understand it? Can you ask something specifically about which part of that whole for loop vs what we explained?
I mean the code itself
just explain me bcz the numbers and variables
are confusing
it prints a specific number of spaces, followed by a specific number of stars
the amount is determined by i
!e
n = 5
for i in range(1, n+1):
print(f"i is {i} ", end='')
print(" " * (n-i), end="")
print("*" * (2*i-1), end="")
print("")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | i is 1 *
002 | i is 2 ***
003 | i is 3 *****
004 | i is 4 *******
005 | i is 5 *********
ik the output bro
I added extra prints so you can follow what's happening
haha yeah, had a typo
should be n-i
!e
n = 5
for i in range(1, n+1):
print(f"i is {i}, {n-i=} spaces, {2*i-1=} stars ", end='')
print(" " * (n-i), end="")
print("*" * (2*i-1), end="")
print("")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | i is 1, n-i=4 spaces, 2*i-1=1 stars *
002 | i is 2, n-i=3 spaces, 2*i-1=3 stars ***
003 | i is 3, n-i=2 spaces, 2*i-1=5 stars *****
004 | i is 4, n-i=1 spaces, 2*i-1=7 stars *******
005 | i is 5, n-i=0 spaces, 2*i-1=9 stars *********
i started to understand
!e
n = 5
for i in range(1, n+1):
print(f"i is {i}, {n-i=} spaces, {2*i-1=} stars ", end='')
print("." * (n-i), end="")
print("*" * (2*i-1), end="")
print("")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | i is 1, n-i=4 spaces, 2*i-1=1 stars ....*
002 | i is 2, n-i=3 spaces, 2*i-1=3 stars ...***
003 | i is 3, n-i=2 spaces, 2*i-1=5 stars ..*****
004 | i is 4, n-i=1 spaces, 2*i-1=7 stars .*******
005 | i is 5, n-i=0 spaces, 2*i-1=9 stars *********
but the main thing is that how would i write a code if i were to draw a different pattern
it entirely depends on the pattern
this isn't universal "draw a pattern" code. Every pattern will be different
show us what that would look like
it's a lot easier to write code to create a shape if you've already created that shape
then you can work backwards
.
I already did that exact one above
what u actually did in that code?
it's multiplying "*" by i
!e
print("*" * 1)
print("*" * 2)
print("*" * 3)
print("*" * 4)
print("*" * 5)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | *
002 | **
003 | ***
004 | ****
005 | *****
it's the same as this, we're just using i and range to make it simpler
Ohh
tysm dude
@jolly ember @turbid anchor Thanks alot
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
we have some great resources here you can look through
ok
but
n = 5
for i in range(n): # OUTTER LOOP FOR ROWS
for j in range(i+1): # INNER LOOP FOR COLOUMNS
print(" ", end=' ')
for j in range(i,n):
print("*", end=' ')
print() #VERY IMPORTANT
***py
n = 5
for i in range(n):# OUTTER LOOP FOR ROWS
for j in range(i+1):# INNER LOOP FOR COLOUMNS
print(" ", end=' ')
for j in range(i,n):
print("*", end=' ')
print()#VERY IMPORTANT
lol this is happening at https://discord.com/channels/267624335836053506/1268174758185402460
ok
n = int(input("Enter the number :"))
for i in range (1, n+1):
print(" " (n-i), end="")
print("" (2*i-1), end="")
print("")*
@jolly ember can u tell me explanation from this line?
the one is bold
I believe I already did. Which one are you talking about?
wait
can i explain to you and check if im wrong
pls do
ok so
welcome
so in first line
you gotta put the input
and make sure u got int
bcz without int the interpreter will think you are giving a string
so
in 2nd line
you print space
and (n-i), end=" " means that n is the input and it will minus 1 from the input like in decreasing order
and the "end=" fuction doesnt print new line so it helps in making these patterns
and 3rd line
we printed a space
Is it a space?
wait sorry its a star
mb
ok so
after that
we did (2*i -1 ) which means, if you see a triangular pattern it has stars in odd numbers
like 1 , 3, 5
thats how it goes
so if we multiply 2 to the i which is the number sequence it will give us the output of the odd numbers
which we need for the construction of triangle
and same function we do ( end = "" )
and then
in the last line u see print with indentation
indentation is quite important
so print( " " ) means that
means what?
wait
if we didnt print the print(" " ) in the end it would give us the new line
we needed a new line
we could've put print("\n")
but it would've give us double line because \n has its own line and print function also gives an extra line
but we need a single line space
so we
only printed and empty print
das it
*** THE END ***
watchu think
nearly perfect
pleasure to hear that
Wdym by "if you see a triangular pattern, it has stars in odd numbers"? Why odd numbers?
because without odd number you wouldnt have a perfect triangle
for example
look at this
you can still get a triangle with running numbers
it starts from 1 then 2 then 3 then 4 and its not a perfect triangle
but the problem is that it will look like this
we need this
maybe you need to use proper terms.
yes you are right
This is a Right-Angle triangle
This is an Equilateral Triangle
or 90 degree one
Right-angles are 90 degrees
real
btw agent
for how long ur doiin pytho
python
I can't remember
Nah. Gettin old bro
tell ya wat?
like how old you got
35
bro what
35 dude
respec fr
didnt know i was talking to a 35 year old
thanks for the help sir
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.