+ 2

How to limit the number of inputs in python syntax input().split() from user ?

The coding should be short as mush as possible

27th Jul 2020, 12:58 PM
Daipayan Mandal
Daipayan Mandal - avatar
2 Answers
+ 9
The clean way would be to take the inputs separately in a loop, just as many as you want, and to check for proper input and communicate with the user. If it has to be short, you could also do something like this: inputs = [input() for i in range(5)] Or, if the input has to come in one line and separated by space, you just throw away the inputs you don't want: inputs = input().split()[:5]
27th Jul 2020, 1:24 PM
HonFu
HonFu - avatar
+ 1
Thank you.After day of searching.But I use like this: inputs = [input() for i in range(n - 1)]
25th Aug 2021, 8:29 AM
Rita Liv
Rita Liv - avatar