python中的nzec运行时错误 [英] nzec runtime error in python

查看:55
本文介绍了python中的nzec运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在我的系统中运行良好.然而,当我在一个在线编译器+调试器中运行时,它给了我一个运行时(NZEC)错误,说第 4 行中的缩进:如果 a.index(min(a)) 是错误的.我期望的解决方案是最外层的 for 循环需要运行 't' 次.据此,我的代码必须是正确的.请帮我找出错误.另外,如果您能告诉我我们什么时候会收到 NZEC 错误,这对我有很大帮助!提前致谢!

This code works fine in my system. However, when i ran in in an online compiler+ debugger, it gave me a runtime(NZEC) error saying indentation in line4:if a.index(min(a)) is wrong. The solution I expect is that the outermost for loop needs to run 't' times. According to that my code has to be right. Please help me find the mistake. Also, if you can tell me when all will we get an NZEC error, it will help me a lot! Thanks in advance!

t = int(raw_input())
for i in range(t):
    a = map(int, raw_input())
    if a.index(min(a)) != 0: 
            if min(a) == 0:
            print a.index(min(a))
        else:
            print str(str(a.index(min(a))) * (min(a)+1))
    elif a.index(min(a)) == 0:
        k = min(a)
        a[0] = 99
        l = min(a)
        if l == k:
            print str(str(a.index(min(a))) * min(a))
        elif l > k:
            print '1'+ ('0' * (k+1))

推荐答案

看起来您的代码混合了制表符和空格.这在 Python 2 中是合法的,但这是一个非常糟糕的主意(它在 Python 3 中已成为一个错误).我怀疑您运行代码的在线解释器正在采取更严格的观点,并将其视为错误.它可能看到类似于 Stack Overflow 看到的内容(您的代码也没有正确复制到您的问题中).

It looks like your code mixes tabs and spaces. That's legal in Python 2, but a very bad idea (it has become an error in Python 3). I suspect that the online interpreter you're running the code in is taking a stricter view, and considering it an error. It probably sees something similar to what Stack Overflow sees (your code didn't copy correctly into your question either).

您可以通过运行带有 -t 标志的 Python 解释器来解决问题,该标志会在标签使用不一致时发出警告,或者 -tt 使其成为一个错误.许多文本编辑器都有将制表符转换为空格的工具,这有助于解决问题.

You can troubleshoot the issue by running the Python interpreter with the -t flag which will emit a warning any time there's inconsistent tab usage, or -tt to make it an error. Many text editors have tools that will convert tabs to spaces which can help to fix the issue.

这篇关于python中的nzec运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆