Nested Loop Triangle

Jason Friedman jsf80238 at gmail.com
Thu May 25 23:49:11 EDT 2017


>
> I need the triangle to be in reverse. The assignment requires a nested
> loop to generate a triangle with the user input of how many lines.
>
> Currently, I get answers such as: (A)
> OOOO
> OOO
> OO
> O
>
> When I actually need it to be like this: (B)
> OOOO
>   OOO
>    OO
>     O
>

Try the rjust string method.

Python 3.6.1 (default, Apr  8 2017, 09:56:20)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("O".rjust(1))
O
>>> print("O".rjust(2))
 O



More information about the Python-list mailing list