【发布时间】:2018-10-23 21:43:18
【问题描述】:
我想要的输出是两个由两个空格分隔的半金字塔。
length = int(input("Enter size of pyramid."))
hashes = 2
for i in range(0, length):
spaces = length - (i+1)
hashes = 2+i
print("", end=" "*spaces)
print("#", end=" "*hashes)
print(" ", end="")
print("#" * hashes)
但是,这最终只打印左金字塔上每一行的第一个哈希值。如果我去掉第 7 行中的end=,金字塔都打印正确,但每行后都有换行符。以下是输出:
结束=:
# ##
# ###
# ####
# #####
没有结束=:
##
##
###
###
####
####
#####
#####
我现在想要的只是第二个输出,但没有换行符。
【问题讨论】:
-
没有新行是什么意思?
-
@DanielMesejo 每行之间没有换行符。
标签: python python-3.x