以下是我正在处理的代码:
def ligneComplete(x,y): #function to print a full line of #
for loop in range(y):
print(x, end = "")
return ligneComplete
def ligneEspace(x,y,z): #function to print a ligne of # with space between
for loop in range(z-2):
print(x, end="")
for loop in range(y-2):
print(" ", end="")
print(x)
return ligneEspace
x = "#"
z = int(input()) #nbcolonne
y = int(input()) #nbligne
print(ligneComplete(x,y)) #print a full ligne of #
print(ligneEspace(x,y,z)) #print ligne with space
#why there is a break line here???????
print(ligneComplete(x,y)) #print full ligne of #
print()
结果如下:
#####
# #
# #
# #
#####
我想这样:
#####
# #
# #
# #
#####
有人可以告诉我为什么在我的功能结束时有一个断线?我试图找到一些答案,但每个主题都是关于添加换行符而不是删除换行符。 非常感谢你的帮助。
答案 0 :(得分:2)
您的代码中存在一些错误:
print()
。你的功能应该是这样的:
def ligneComplete(x,y): #function to print a full line of #
for _ in range(y):
print(x, end = "")
print()
def ligneEspace(x,y,z): #function to print a ligne of # with space between
for _ in range(z-2):
print(x, end="")
for _ in range(y-2):
print(" ", end="")
print(x)
x = "#"
z = 5 #int(input()) #nbcolonne
y = 5 #int(input()) #nbligne
ligneComplete(x,y) #print a full ligne of #
ligneEspace(x,y,z) #print ligne with space
ligneComplete(x,y) #print full ligne of #
输出:
#####
# #
# #
# #
#####
答案 1 :(得分:0)
看起来你不想在打电话时打印这些功能。这些函数自己调用print()。
ligneComplete(x,y) #print a full ligne of #
ligneEspace(x,y,z) #print ligne with space
#why there is a break line here???????
ligneComplete(x,y) #print full ligne of #
print()
答案 2 :(得分:0)
def ligneComplete(x,y): #function to print a full line of #
for loop in range(y):
print(x, end = "")
def ligneEspace(x,y,z): #function to print a ligne of # with space between
for loop in range(z-2):
print(x, end="")
for loop in range(y-2):
print(" ", end="")
print(x, end='')
x = "#"
z = int(input()) #nbcolonne
y = int(input()) #nbligne
ligneComplete(x,y) #print a full ligne of #
ligneEspace(x,y,z) #print ligne with space
ligneComplete(x,y) #print full ligne of #
print()
会奏效。