stdin.readline()在jupyter笔记本中显示错误,但在终端中显示错误,为什么?

问题描述 投票:0回答:1

我想从用户那里得到一个字符串作为输入,并将其中用空格分隔的数字存储到列表中。

#input:
'1 2 3 4 5'

#output:
[1,2,3,4,5]

list(map(int,list(stdin.readline().split(' '))))

在jupyter笔记本中运行时给出ValueError: invalid literal for int() with base 10: '',但在命令行中运行时效果很好。为什么会这样呢?我搜索了错误并得到了此stack overflow question,所以我尝试了list(map(int,list(map(float,stdin.readline().split(' ')))))但是现在我得到这个错误:ValueError: could not convert string to float:

python jupyter-notebook
1个回答
0
投票

尝试这个简单的解决方案

© www.soinside.com 2019 - 2024. All rights reserved.