简体   繁体   English

从用户那里获取多个输入,以行分隔

[英]Take multiple inputs from user seperated by lines

I've been trying different variations of this simple piece of code and it won't take the input.我一直在尝试这段简单代码的不同变体,它不会接受输入。 Both split('\n') and splitlines() don't work. split('\n') 和 splitlines() 都不起作用。

a,b = input().split('\n')
#User input as given below
2
3
4

When I try to give the input on different lines, I get the error ' ValueError: not enough values to unpack'.当我尝试在不同的行上提供输入时,我收到错误“ValueError: no enough values to unpack”。 Is there a way to work around this without assigning the values to a list but different variables?有没有办法在不将值分配给列表但不同的变量的情况下解决这个问题? Please help.请帮忙。

I've been trying different variations of this simple piece of code and it won't take the input.我一直在尝试这段简单代码的不同变体,它不会接受输入。 Both split('\n') and splitlines() don't work. split('\n') 和 splitlines() 都不起作用。

a,b = input().split('\n')
#User input as given below
2
3
4

When I try to give the input on different lines, I get the error ' ValueError: not enough values to unpack'.当我尝试在不同的行上提供输入时,我收到错误“ValueError: no enough values to unpack”。 Is there a way to work around this without assigning the values to a list but different variables?有没有办法在不将值分配给列表但不同的变量的情况下解决这个问题? Please help.请帮忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM