
November 29th, 2012, 09:52 AM
|
 |
Contributing User
|
|
Join Date: May 2012
Location: 39N 104.28W
Posts: 90
Time spent in forums: 1 Day 13 h 41 m 29 sec
Reputation Power: 2
|
|
Quote: | 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
>>>
|