对 Python 非常陌生,我就是不知道是什么导致了我的代码中的错误消息......
It says '[pylint] E0001:invalid syntax (<string>, line 24)'.
有人可以解释一下我在这里缺少什么吗?
非常感谢!
#########################################
# Draws a mario-style right-side-aligned half pyramid
# of the requested height.
# Restriction: 0 < height < 23
##########################################
while True:
height = int(input("Height: "))
if height > 0 and height < 23:
break
elif height == 0:
print()
print()
print()
print("I have drawn a pyramid with a height of 0!")
print("Isn't it pretty!")
exit(0)
hashes = 2
for i in range(height):
spaces = (height - hashes + 1)
for j in range(spaces):
print(" ", end="")
for k in range(hashes):
print("#", end="" )
print()
hashes += 1
最佳答案
您正在使用 python2,应该更改:
print(" ", end="")
print("#", end="" )
至:
print(" "),
print("#"),
<小时/>
此外
你可能应该改变:
print()
到
print("")
并且可以通过使用翻译 rowbreak 的“\n”来减少这种“美感”。
print()
print()
print()
print("I have drawn a pyramid with a height of 0!")
print("Isn't it pretty!")
至:
print("\n\n\nI have drawn a pyramid with a height of 0!\nIsn't it pretty!")
关于python - 为什么语法无效(<string>,第 24 行)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46545136/