0
How to enter list of given range of elements at a time,plz check description
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
14 Réponses
+ 1
As you want your L list to be int you can just add [:6] after split function in your solution
L=[int(x) for x in input().split()[:6]]
+ 2
if suppose you provide your input data may be we could get a clear understanding about the issue
+ 1
the thing is you don't need a loop for this input.
you can use a slice operation for this like
L=input ().split()[:6]
0
you mean like six different list of numbers?
0
S,6 different integers in same list
0
maybe you can try using two for loops like
L=[[int(y) for y in input().split()] for x in range(6)]
0
Iam getting error message
0
what error message
0
mylist = [int(input()) for x in range(6)]
print(mylist)
# or
size = int(input())
mylist = [int(input()) for x in range(size)]
print(mylist)
You can also use an underscore instead of the 'x' above.
0
Sathish Kanna once try to execute it
0
rodwynnejones u haven't used split function
0
I/p:-5 2 0 8 9 0
Ur approach is correct but it is showing EOF error
0
Give example input.
0
Thank u Sathish Kanna rodwynnejones