gpt4 book ai didi

python - 为什么语法无效(,第 24 行)?

转载 作者:行者123 更新时间:2023-12-01 02:33:20 26 4
gpt4 key购买 nike

对 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com