Hey everybody,
Hope everything goes well,
As I am a newcomer in Python, I have difficulty in understanding the way Python calculate nested loops.
Here is my exact question:
I'm trying to print triangle with stars,
line 1: for num in range (6):
line 2: stars = ' '
line 3: for x in range(num):
line 4: stars += '*'
line 5: print(stars)
Output:
line 1: null
line 2: *
line 3: **
line 4: ***
line 5: ****
line 6: *****
--------------------------------------------------------------------
What I've found is that when I write line 1, the Python considers 6 row, and for line 3, Python considers 5 columns. when num=0 , x=null, and for num=1 , x=0, and so on.
why for num=0 Python collect x=null?
Thank you so much in advance for your consideration
Hope everything goes well,
As I am a newcomer in Python, I have difficulty in understanding the way Python calculate nested loops.
Here is my exact question:
I'm trying to print triangle with stars,
line 1: for num in range (6):
line 2: stars = ' '
line 3: for x in range(num):
line 4: stars += '*'
line 5: print(stars)
Output:
line 1: null
line 2: *
line 3: **
line 4: ***
line 5: ****
line 6: *****
--------------------------------------------------------------------
What I've found is that when I write line 1, the Python considers 6 row, and for line 3, Python considers 5 columns. when num=0 , x=null, and for num=1 , x=0, and so on.
why for num=0 Python collect x=null?
Thank you so much in advance for your consideration
buran write Jan-09-2021, 05:53 PM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Also, don't include line numbers with your code
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Also, don't include line numbers with your code