I have this code to print ‘H’ in a pattern using ‘*’:
def grid_h():
result_str='';
for row in range(5):
for column in range(5):
if((column == 0 or column == 4)
or (row == 2)):
result_str = result_str + '*'
else:
result_str = result_str + ' '
result_str = result_str + '\n'
return result_str
I’m trying to print HH in the same line but it always go to the new line.
I know there is an end=” at Python 3 to stay in the same line but I have tried this and still not working:
print(grid_h(), end=”), print(grid_h())
>Solution :
Just as @tripleee has mentioned in the comment, I think you should read the guidelines on how to ask questions.
anyway, just to give you a hint, your function returns this unformatted string: '* *\n* *\n*****\n* *\n* *\n'
Doesn’t matter whether you have the end='' flag in print() or not, the newline is included in that string that your grid_h() function returns.
If you want the H logo thingy to be side by side, then you need to figure out how to fix where the \n character is placed…