我想从用户那里得到一个字符串作为输入,并将其中用空格分隔的数字存储到列表中。
#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:
尝试这个简单的解决方案