By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 2,114 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

Python Upside Down Triangle using For loop

P: 3
Expand|Select|Wrap|Line Numbers
  1. def print_row(col_count):
  2.    for col in range(col_count):
  3.       print "*",
  4.    print
  5.  
  6. def print_rect(act_len):
  7.    for row in range(act_len):
  8.       print_row(row)
  9.  
  10. leg_len = int(raw_input("How long are the legs of the triangle?\n"))
  11. act_len = leg_len +1
  12. print_rect(act_len)
  13. 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.
Sep 22 '11 #1
Share this Question
Share on Google+
2 Replies


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

Rabbit
Expert Mod 10K+
P: 12,383
Take the length, subtract 1, and subtract the row number.
Sep 22 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.