Thank you for looking at my issue. I am a beginner in school and we have an excercise that asks us to write a program that uses nestes loos to draw this patter:

``````*******
******
*****
****
***
**
*
``````

and

``````**
* *
*  *
*   *
*    *
*     *
``````

I am not looking for anyone to do this for me, I actually do want to learn what I am missing.

So I figured out if I us this code

``````def main():
start = 7

for r in range(start):
for c in range(r):
print('*', end='')
print('*')

main()
``````

I can get a pyramid like

``````*
**
***
****
*****
******
*******
``````

What am I missing there? If I learn I think I can figure out the second one. Thanks in advance for any help.

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by snippsat

Hint ...

``````start = 7
# this will count r from start down to 0
for r in range(start, -1, -1):
print(r)
``````

Thank you very much. I get the step value counting down and was able to get the correct outcome but I am confused on the ending value (-1) and why that made it work.

Edited by nUmbdA

I get the step value counting down and was able to get the correct outcome but I am confused on the ending value (-1) and why that made it work.

``````>>> start = 7
>>> stop = 1
>>> step = -1
>>> for r in range(start,stop,step):
r
7
6
5
4
3
2

>>> help(range)
Help on built-in function range in module __builtin__:

range(...)
range([start,] stop[, step]) -> list of integers

Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
When step is given, it specifies the increment (or decrement).
For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
These are exactly the valid indices for a list of 4 elements.
``````