-1

I need to reverse the output format of a printed triangle using O's

my code is

userRows=int(input("Enter a positive number less than or equal to 20!"));

while((userRows>21) or (userRows<0)):
      userRows=int(input("Try again! Please enter a positive number less than or equal to 20."));

rows=1;
while(rows<=userRows):
    columns=1;
    while(columns<=rows):
        print("O",end='');
        columns=columns+1;
    print('');    
    rows=rows + 1;

the output is

Enter a positive number less than or equal to 20!20
O
OO
OOO
OOOO
OOOOO
OOOOOO
OOOOOOO
OOOOOOOO
OOOOOOOOO
OOOOOOOOOO
OOOOOOOOOOO
OOOOOOOOOOOO
OOOOOOOOOOOOO
OOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOOOO

I'm trying to get this to align from right to left, instead of left to right(as shown above).

user284635
  • 33
  • 5
  • so put in some extra code to print as many spaces as there AREN'T o's on the line. – Marc B Oct 29 '14 at 16:32
  • possible duplicate of [fill out a python string with spaces?](http://stackoverflow.com/questions/5676646/fill-out-a-python-string-with-spaces) – Patrick M Oct 29 '14 at 16:38

2 Answers2

0

print n(user input - number of iteration )white space before print 'o'

def displayTriganle(userInput):
        [print(' '*(userInput-i)+ 'o'*i) for i in range(1,userInput+1)]


                   o
                  oo
                 ooo
                oooo
               ooooo
              oooooo
             ooooooo
            oooooooo
           ooooooooo
          oooooooooo
         ooooooooooo
        oooooooooooo
       ooooooooooooo
      oooooooooooooo
     ooooooooooooooo
    oooooooooooooooo
   ooooooooooooooooo
  oooooooooooooooooo
 ooooooooooooooooooo
oooooooooooooooooooo
galaxyan
  • 5,119
  • 2
  • 15
  • 36
0
>>> userRows=int(input("Enter a positive number less than or equal to 20!"));
Enter a positive number less than or equal to 20!20
>>> for i in range(userRows):
...    print ' '*(userRows-i)+'0'*i
... 

                   0
                  00
                 000
                0000
               00000
              000000
             0000000
            00000000
           000000000
          0000000000
         00000000000
        000000000000
       0000000000000
      00000000000000
     000000000000000
    0000000000000000
   00000000000000000
  000000000000000000
 0000000000000000000
Irshad Bhat
  • 7,301
  • 1
  • 19
  • 30