gpt4 book ai didi

Python 3 错误 : ValueError: invalid literal for int() with base 10: ''

转载 作者:太空宇宙 更新时间:2023-11-04 08:50:46 27 4
gpt4 key购买 nike

我已经编写了解决问题的代码。

这是我的代码:

t=int(input())
print("")
while(t):
s=0
n=int(input())
for i in range(n):
no=int(input())
s=s+no
if s%n==0:
print("YES")
else:
print("NO")
print("")
t-=1

当我在 OS X 终端上运行它时,它工作正常。但是当我在 IDEone 上运行它或将其作为解决方案提交时,它在 第 5 行 上给出了一个错误:

ValueError: invalid literal for int() with base 10: ''

我不确定是什么问题。

最佳答案

如果用户没有输入任何内容,换句话说就是空字符串,则您不会处理

>>> int('')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
int('')
ValueError: invalid literal for int() with base 10: ''

您可以使用 a variety of techniques更稳健地接受来自用户的输入。

关于Python 3 错误 : ValueError: invalid literal for int() with base 10: '' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35629098/

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