<p>嘿,伙计们,我正在学习python,但我被困在了这个问题上。我试过了,但我的输出不符合正确的答案。有什么原因,怎么解决?在</p>
<p><strong>问题:</strong>刺客游戏是一个在大学校园里玩的简单游戏,每个玩家只要对他们说一声“你死了”,就可以指定一个目标进行暗杀。当然,校园里有成千上万的人,而游戏中只有几十个人,你永远不知道谁在暗杀你。一旦你刺杀了某人,你就瞄准了他们要找的目标。如果这是你,那么你就是赢家。为了确保这项工作正常进行,目标必须形成一个连续的“链”。编写一个程序,允许用户输入他们的目标分配,并根据是否存在连续的“链”进行输出。列表中的每个人都用列表中的位置来表示。这个位置的价值就是他们的目标。在</p>
<p><strong>我的代码:</strong></p>
<pre><code>total=0
list_of_players=[]
player=raw_input("Enter a player (end to stop): ")
while player !="end":
list_of_players.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(int(player))
player=raw_input("Enter a player (end to stop): ")
for x in range(len(list_of_players)):
total+=1
if list_of_players[x]==0 and len(list_of_players)==total:
print "The game is valid."
if list_of_players[x]!=0 or len(list_of_players)!=total:
print "The game is not valid. "
</code></pre>
<p>该问题指出,如果我<strong>输入玩家4,3,0,5,6,2,1:</strong>它应该是<strong>有效的</strong>。
我的程序将其显示为<strong>无效</strong>。
有什么办法改进我的计划吗?
我从programmersheaven.com网站如果有人好奇的话!
谢谢!在</p>