Python – Printing an upside down triangle in Python 3.4.2?

loopspythonpython-3.x

So, for my programming class I am supposed to write a program that outputs this:

oooooo
ooooo
oooo
ooo
oo
o

I have been able to make it so that the program outputs the triangle right side up but even after looking for help online, I haven't been able to find the solution to turning the triangle upside down. Here is my code:

def main():

base_size = 6

for r in range (base_size):
    for c in range (r + 1):
        print('o', end = '')
    print()

main()

And this is the output I get:

o
oo
ooo
oooo
ooooo
oooooo

Can someone help me out? I am a newbie so this is kind of tough for me even though it's probably pretty simple for you guys.

Thanks in advance!

Best Solution

You're very close. You can use the range function, but step using -1 to walk from n to 0.

You can also make a string by multiplying a character by an integer.

def triangle(n):
    for i in range(n, 0, -1):
        print('o' * i)

Testing

>>> triangle(6)
oooooo
ooooo
oooo
ooo
oo
o