Python Codechef上的NZEC错误
我是codechef的新手,它给了我下面代码的NZEC错误。我已经彻底搜索过了,但找不到解决问题的办法Python Codechef上的NZEC错误,python,Python,我是codechef的新手,它给了我下面代码的NZEC错误。我已经彻底搜索过了,但找不到解决问题的办法 t=int(原始输入())#接受输入 i=1 当我不投票时: 印刷“蛇” elif mon_投票>sna_投票: 打印“猫鼬” 其他: 打印“领带” 首先,让我告诉您您遇到了什么错误。这是正在执行的代码 你遇到的问题是 EOF:读取一行时EOF 之所以发生这种情况,是因为循环中的i没有递增,因此出现了无限循环情况 循环结束后,只需将i增加1,您的问题就会得到解决。希望能有帮助 编辑 在此之后
t=int(原始输入())#接受输入
i=1
当我不投票时:
印刷“蛇”
elif mon_投票>sna_投票:
打印“猫鼬”
其他:
打印“领带”
首先,让我告诉您您遇到了什么错误。这是正在执行的代码
你遇到的问题是
EOF:读取一行时EOF
之所以发生这种情况,是因为循环中的i
没有递增,因此出现了无限循环情况
循环结束后,只需将i
增加1,您的问题就会得到解决。希望能有帮助
编辑
在此之后,您可能会面临的另一个问题是由于代码中的输入错误。我想
elec_list[index-1]='
应更改为elec_list[index-1]='
首先,让我告诉您发生了什么错误。这是正在执行的代码
你遇到的问题是
EOF:读取一行时EOF
之所以发生这种情况,是因为循环中的i
没有递增,因此出现了无限循环情况
循环结束后,只需将i
增加1,您的问题就会得到解决。希望能有帮助
编辑
在此之后,您可能会面临的另一个问题是由于代码中的输入错误。我想
elec_-list[index-1]=''应更改为elec_-list[index-1]=''
将所有代码放入Try中,除了因为Codechef使用文件作为输入之外。我在我的代码中也做了同样的操作,它正在工作。
try:
t= int(raw_input()) #accepts input
i = 1
while i <= t:
input_str = raw_input() #accepts the input for further working
elec_list = [] #empty list to store individual string elements
for animal in input_str: #reiterating over each element of string
elec_list.append(animal) #and adding to our list
#now we will go over elec_list and make mongoose eat at most one of their adjacent snakes.
for index, animal in enumerate(elec_list):
if animal == 'm':
if index and index != len(elec_list):
if elec_list[index - 1] == 's':
elec_list[index - 1] = ''
elif elec_list[index + 1] == 's':
elec_list[index + 1] = ''
elif not index:
if elec_list[index + 1] == 's':
elec_list[index + 1] = ''
elif index == len(elec_list):
if elec_list[index - 1] == 's':
elec_list[index - 1] == ''
#now counting the number of snakes and mongooses.
mon_vote = elec_list.count('m')
sna_vote = elec_list.count('s')
#printing the output
if sna_vote > mon_vote:
print("snakes")
elif mon_vote > sna_vote:
print("mongooses")
else:
print("tie")
except:
pass
试试看:
t=int(原始输入())#接受输入
i=1
当我不投票时:
印刷品(“蛇”)
elif mon_投票>sna_投票:
印刷品(“猫鼬”)
其他:
打印(“领带”)
除:
通过
将所有代码放在Try中,因为Codechef使用文件作为输入。我在我的代码中也做了同样的操作,它正在工作。
try:
t= int(raw_input()) #accepts input
i = 1
while i <= t:
input_str = raw_input() #accepts the input for further working
elec_list = [] #empty list to store individual string elements
for animal in input_str: #reiterating over each element of string
elec_list.append(animal) #and adding to our list
#now we will go over elec_list and make mongoose eat at most one of their adjacent snakes.
for index, animal in enumerate(elec_list):
if animal == 'm':
if index and index != len(elec_list):
if elec_list[index - 1] == 's':
elec_list[index - 1] = ''
elif elec_list[index + 1] == 's':
elec_list[index + 1] = ''
elif not index:
if elec_list[index + 1] == 's':
elec_list[index + 1] = ''
elif index == len(elec_list):
if elec_list[index - 1] == 's':
elec_list[index - 1] == ''
#now counting the number of snakes and mongooses.
mon_vote = elec_list.count('m')
sna_vote = elec_list.count('s')
#printing the output
if sna_vote > mon_vote:
print("snakes")
elif mon_vote > sna_vote:
print("mongooses")
else:
print("tie")
except:
pass
试试看:
t=int(原始输入())#接受输入
i=1
当我不投票时:
印刷品(“蛇”)
elif mon_投票>sna_投票:
印刷品(“猫鼬”)
其他:
打印(“领带”)
除:
通过
index
永远不等于len(elec\u列表)
index
永远不等于len(elec\u列表)
。您的caps lock钥匙被锁定您的caps lock钥匙被锁定