#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0

    Printing multiple lines in a user input range?


    I need help with programming something in python

    I need to take the users input on how many lines to print of x, then print that line and all lines prior

    For example if the user in puts 7 lines, I need the program to evaluate

    x
    xx
    xxx
    xxxx
    xxxxx
    xxxxxx
    xxxxxx

    I have tried using the current code with a for loop and a range, but am still having problems, can anyone point me in the right direction?

    def main():
    n = input("How many lines would you like to print?"
    for n in range (0,100)
    print: "x" * n

    I was thinking this would work, but I keep on getting an error in regards to the print portion. Anyone know where I am going wrong?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    157
    Rep Power
    2
    Originally Posted by brod615
    I need help with programming something in python

    I need to take the users input on how many lines to print of x, then print that line and all lines prior

    For example if the user in puts 7 lines, I need the program to evaluate

    x
    xx
    xxx
    xxxx
    xxxxx
    xxxxxx
    xxxxxx

    I have tried using the current code with a for loop and a range, but am still having problems, can anyone point me in the right direction?

    def main():
    n = input("How many lines would you like to print?"
    for n in range (0,100)
    print: "x" * n

    I was thinking this would work, but I keep on getting an error in regards to the print portion. Anyone know where I am going wrong?
    The print statement (or function in v3.x) doesn't take ":"s.

    Code:
    >>> n=int(raw_input('number of lines '))
    number of lines 8
    >>> for i in xrange(n): print i*'x'
    ...
    
    x
    xx
    xxx
    xxxx
    xxxxx
    xxxxxx
    xxxxxxx
    >>>

IMN logo majestic logo threadwatch logo seochat tools logo