Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x ValueError:以10为基数的int()的文本无效:'\r';_Python 3.x - Fatal编程技术网

Python 3.x ValueError:以10为基数的int()的文本无效:'\r';

Python 3.x ValueError:以10为基数的int()的文本无效:'\r';,python-3.x,Python 3.x,我实际上是想把一个字符转换成一个整数。 (即“1”到1),但它显示了一些错误 ValueError: invalid literal for int() with base 10: '\r' 为什么它无法转换它。 如果我在Geeksforgeks编译器上运行它,它不会显示任何错误。 但在提交时,它显示了这个错误 t=int(input()) for each in range(t): s=input() count=0 num=0 for eachch in str(s): if (

我实际上是想把一个字符转换成一个整数。 (即“1”到1),但它显示了一些错误

ValueError: invalid literal for int() with base 10: '\r' 
为什么它无法转换它。 如果我在Geeksforgeks编译器上运行它,它不会显示任何错误。 但在提交时,它显示了这个错误

t=int(input())
for each in range(t):
s=input()
count=0
num=0
for eachch in str(s):
    if (eachch>='a') and (eachch<='z'):
        count+=1
    else:
        num=num*10+int(eachch)
if(int(num) == int(count)):
    print("1")
else:
    print("0")
t=int(输入())
对于范围(t)内的每一个:
s=输入()
计数=0
num=0
str中的每种HCH:

如果(eachch>='a')和(eachch,这里的问题一定是您得到的输入字符串有
\r
符号,因此
int()
函数无法从中得到整数。使用
strip()
函数在这里必须有所帮助


例如,
t=int(input().strip())

这里的问题一定是您得到的输入字符串有
\r
符号,因此
int()
函数无法从中得到整数。使用
strip()
函数在这里必须有所帮助


例如,
t=int(input().strip())
\r
是一个CR字符——回车符。当您在DOS/Windows平台上构建输入(其中行以CRLF结尾,又称
\r\n
)并将其馈送到UNIX平台上运行的程序(其中行仅以LF结尾,又称
\n
)时,它们往往会出现.@Piyush Yadav,你应该修正代码中的缩进
\r
是一个CR字符——回车符。当你在DOS/Windows平台上构建输入(其中行以CRLF结尾,又称
\r\n
)并将其输入到UNIX平台上运行的程序(其中行仅以LF结尾,又称
\n
)时,缩进会出现@Piyush Yadav,你应该修正代码中的缩进