how to enter range of numbers at a time in single line of list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to enter range of numbers at a time in single line of list

26th Dec 2020, 5:40 PM
Krid Indu
Krid Indu - avatar
10 Answers
+ 1
numbers = list(map(int, input().split()))[:6]
26th Dec 2020, 6:44 PM
Roma Butaku
Roma Butaku - avatar
+ 1
the number in square brackets indicates the number of elements to enter
26th Dec 2020, 6:47 PM
Roma Butaku
Roma Butaku - avatar
0
var = list(range(x1, x2))
26th Dec 2020, 5:48 PM
Calvin Thomas
Calvin Thomas - avatar
0
User has to enter list of elements
26th Dec 2020, 5:52 PM
Krid Indu
Krid Indu - avatar
0
Eg:-i/p:-n=5 I/p:-6 1 9 5 4 How to take range of elements input at a single line
26th Dec 2020, 5:54 PM
Krid Indu
Krid Indu - avatar
0
KRID Indu Do you mean to construct a list with the range supplied by the user? In that case, you can use int(input()).
26th Dec 2020, 5:57 PM
Calvin Thomas
Calvin Thomas - avatar
0
Else, if your intention is to find out the range of a set of numbers, you can use the min()/max() function.
26th Dec 2020, 5:58 PM
Calvin Thomas
Calvin Thomas - avatar
0
Nope
26th Dec 2020, 5:59 PM
Krid Indu
Krid Indu - avatar
0
L=[int(x) for x in input().split()] -->any number of integers intake But i want to take elements according to user requirement like L=[int(x) for x in range(6).input().split()]-->but its not working
26th Dec 2020, 6:03 PM
Krid Indu
Krid Indu - avatar
0
This 6 elements user has to enter seperated by spaces like 8 7 4 5 0 7 8
26th Dec 2020, 6:04 PM
Krid Indu
Krid Indu - avatar