Pages

Sunday, 23 June 2013

how to use for statement in Python

usually for statement is used with range (and xrange)

for var in list or tuple (-> range or xrange)
      statement




for example, to print out
*
**
***
****
  .
  .
*. . . . .****
as many as we want


to do this,
we need two for statement.

=============================================
intvalue = input("Enter integer value :")
"""intvalue = int(raw_input("Enter integer value :"))"""

for firstfor in range(intvalue):
    for secondfor in range(firstfor+1):
        print "*",
    print

==============================================

No comments:

Post a Comment