Python 错误:取消缩进与任何外部取消缩进限制不匹配
正如你所看到的,我是一个编程新手,并且是从 Python 开始的,上述错误发生在突出显示的代码行上。 怎么骑过去这个...
import random
secret= random.randint (1,100)
guess=0
tries=0
print "AHOY! I am the dead pirate Roberts, and I ahve a secret!"
print "It is a number from 1 to 99. I will give you six tries."
while guess !=secret and tries <6:
guess= input("what's yer guess? " )
if guess < secret :
print "Too Low, ye curvy dog!"
elif guess > secret:
print "Too high, landlubber!"
tries= tries +1
***if guess == secret :***
print "Avast! Ye got it! found my secret, ye did!"
else:
print "No more guesses! Better luck next time, matey!"
print "The secret number was ", secret"
As you can see I am a novice in Programming and started with Python, the above said error is occurring on the highlighted line of code.
How to ride over this...
import random
secret= random.randint (1,100)
guess=0
tries=0
print "AHOY! I am the dead pirate Roberts, and I ahve a secret!"
print "It is a number from 1 to 99. I will give you six tries."
while guess !=secret and tries <6:
guess= input("what's yer guess? " )
if guess < secret :
print "Too Low, ye curvy dog!"
elif guess > secret:
print "Too high, landlubber!"
tries= tries +1
***if guess == secret :***
print "Avast! Ye got it! found my secret, ye did!"
else:
print "No more guesses! Better luck next time, matey!"
print "The secret number was ", secret"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Python 使用缩进来表示代码块。代码的缩进无效(相关
if
的缩进与之前的任何块都不对齐;快速浏览一下代码,至少还有一个错误)。以下是 Python 中缩进工作原理的简短清晰解释: http://diveintopython.net/getting_to_know_python/indenting_code .html
Python uses indentation to denote code blocks. The indentation of your code is not valid (the indentation of the
if
in question doesn't line up with any previous block; from a quick look over the code, there's at least one more error).The following is a short clear explanation of how indentation works in Python: http://diveintopython.net/getting_to_know_python/indenting_code.html
在 python 中,块之间必须保持恒定的缩进。
在
if 猜测
中Secret:
代码块,缩进比 while 代码块中的缩进长得多。正确的代码是:
In python, you must keep a constant indentation between your blocks.
And in the
if guess < secret:
code block, the indentation is much longer than in the while code block.The proper code is :