【发布时间】:2016-03-29 11:54:59
【问题描述】:
似乎无法弄清楚我在 python 中的间距是怎么回事。我正试图让它打印出来:
Two Vertical Lines, height=3; width=3:
* *
* *
* *
Two Vertical Lines, height=4; width=5:
* *
* *
* *
* *
Two Vertical Lines, height=5; width=2:
**
**
**
**
**
但使用此代码:
def two_vertical_lines (height, width):
for x in range (0, height):
if width > 2:
new_width = width - 2
mult2 = " " * new_width
print ("*",mult2,"*", "\n", end='')
else:
print ("**", "\n", end='')
return
由于某种原因,我的程序正在返回:
Two Vertical Lines, height=3; width=3:
* *
* *
* *
Two Vertical Lines, height=4; width=5:
* *
* *
* *
* *
Two Vertical Lines, height=5; width=2:
**
**
**
**
**
(请注意两条垂直线之间的间距/宽度差异,即使我的变量 new_width 在技术上应该是 1 个空格)
【问题讨论】:
-
您的代码没有任何问题...我的 PyCharm 中显示的内容非常好...也许您想弄清楚打印它们的方式?
标签: python string python-3.x spacing