totalRows = int(raw_input ("Please enter a number: ")) 

for currentRow in range(1, totalRows+1): 
    for currentCol in range (1, currentRow+1): 
        print '*',
    print
print

for currentRow in range (1, totalRows+1): 
    for currentCol in range(1, currentRow+1): 
    
        print '*', 
    print

Output

*
* *
* * *
* * * *

*
* *
* * *
* * * *

Having some problems trying to rearrange this code so that this output prints instead. So basically the bottom triangle should mirror the top but all my logical approaches such as reversing the for loop hasn't worked at all. Any step into the right direction would be greatly appreciated

*
* *
* * *
* * * *

* * * *
* * *
* *
*

You can use the code you have with a range from total rows to zero and a step of -1, or a counter for the number of stars to print.

total_rows = 5

num_stars = total_rows
for row in range (total_rows): 
    print '*' * num_stars
    num_stars -= 1

Like this?

totalRows = int(raw_input ("Please enter a number: ")) 

for currentRow in range(1, totalRows + 1):
    print '* ' * currentRow

print

for currentRow in reversed(range(1, totalRows + 1)): 
    print '* ' * currentRow

So there is an actual 'reversed' command? I had no idea. Simplifies everything I already had done. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.