Python Upside Down Triangle using For loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tony14067
    New Member
    • Sep 2011
    • 3

    Python Upside Down Triangle using For loop

    Code:
    def print_row(col_count):
       for col in range(col_count):
          print "*",
       print
    
    def print_rect(act_len):
       for row in range(act_len):
          print_row(row)
    
    leg_len = int(raw_input("How long are the legs of the triangle?\n"))
    act_len = leg_len +1
    print_rect(act_len)
    print "Bye!"
    How long are the legs of the triangle?
    5
    *
    * *
    * * *
    * * * *
    * * * * *
    Bye!

    So above is the program I have so far which gets the legs of the triangle and prints it right side up. Any helpful hints on how to turn the triangle upside down would be much appreciated. Thanks.
    Last edited by bvdet; Sep 25 '11, 04:38 PM. Reason: Add code tags
  • tony14067
    New Member
    • Sep 2011
    • 3

    #2
    sorry, i'm using:
    python 2.7.1
    on linux2
    GCC 4.6.0
    with gedit to write the program

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Take the length, subtract 1, and subtract the row number.

      Comment

      Working...