def number0(width, height, symbol):
toporbottom = ("*"*5)
middle = ("* *")
result = toporbottom + "\n" + (middle) * height + "\n" + toporbottom
return result
result = number0(5, 5, "*")
print (result)
这是我运行程序时会发生什么:
*****
* ** ** ** ** *
*****
我想在中间和高度之间添加换行符,使其看起来像一个高度为5的0形状。
答案 0 :(得分:2)
尝试将order-md-2
更改为middle = ("* *")
。并且不要在构建结果中使用最后middle = "* *\n"
。
答案 1 :(得分:0)
也许:结果= toporbottom +“\ n”+(中间+“\ n”)*身高+ toporbottom
答案 2 :(得分:0)
你只需要改变:
middle = ("* *")
middle = ("* *\n")
和
result = toporbottom + "\n" + (middle) * height + "\n" + toporbottom
result = toporbottom + "\n" + (middle) * height + toporbottom
。<强>代码:强>
def number0(width, height, symbol):
toporbottom = ("*"*5)
middle = ("* *\n")
result = toporbottom + "\n" + (middle) * height + toporbottom
return result
result = number0(5, 5, "*")
print (result)
<强>输出:强>
*****
* *
* *
* *
* *
* *
*****
ps:现在您应该将"*"
和middle
中的硬编码符号toporbottom
更改为函数参数symbol
。
答案 3 :(得分:0)
您只需使用(2):
更改当前代码(1)1) middle = ("* *")
result = toporbottom + "\n" + (middle) * height + "\n" + toporbottom
2) middle = "* *\n"
result = toporbottom + "\n" + (middle) * height + toporbottom
因此修改后的代码将是:
def number0(width, height, symbol):
toporbottom = ("*"*5)
middle = "* *\n"
result = toporbottom + "\n" + (middle) * height + toporbottom
return result
result = number0(5, 5, "*")
print (result)
这应该可以解决问题