This is in python language. I need to print this pattern, depending on the number of lines a user enters:
'##'
'# #'The next pattern is three spaces away and so on...
This is my code but it prints the second number 开发者_Python百科sign on a different line. I need them to go on the same line.
def drawPatternIII (lines):
for i in range(lines):
for j in range(1):
print('#')
for j in range(i+1):
print (' ', end = '')
print ('#')
please help!
You would need to add end=""
to the first print()
call. While you are at it, remove the pointless for loop with a single iteration.
A concise alternative would be
for i in range(lines):
print("#" + " "*i + "#")
The one liner version!
def drawPatternIII (lines):
list(map(print,["#" + " "*i + "#" for i in range(lines)]))
精彩评论