【发布时间】:2021-07-26 05:54:44
【问题描述】:
代码:
triangle_char = input('Enter a character:\n')
triangle_height = int(input('Enter triangle height:\n'))
print('')
for i in range(triangle_height):
updatedChar = ' '.join([triangle_char]*i)
print(triangle_char + ' ' + updatedChar + ' ')
i += 1
输出是正确的,但在第一次迭代结束时我似乎无法摆脱额外的“”空格。
Example Output:
% # How to remove this whitespace but keep the others
% %
% % %
【问题讨论】:
-
你能解释一下你的预期输出是什么样的
-
旁注:
i +=1对我来说似乎很臭,你已经在循环使用for循环,i将自动更新。
标签: python for-loop whitespace