0

can anyone explain me what is input() for in range(int(input()))

x = [input() for i in range(int(input()))] Why ther is input() before for ??

26th Aug 2020, 2:10 PM
Smiley[Offline]
10 Answers
+ 3
That's a list comprehension. If you want to figure out how these work, read this: https://code.sololearn.com/ck6HicJ6Z8jG/?ref=app
26th Aug 2020, 2:11 PM
HonFu
HonFu - avatar
0
It will make a list of string with a length of int(input()) for example : if you put 10 for int(input()) it will take 10 string values as input from you and make them into a list
26th Aug 2020, 2:13 PM
Hamza Rarani
Hamza Rarani - avatar
0
HonFu sorry can't understand pls simplyfy it for me
26th Aug 2020, 2:13 PM
Smiley[Offline]
0
Hamza Rarani sir I was asking that why there is input() before for ?
26th Aug 2020, 2:16 PM
Smiley[Offline]
0
smiley it is for taking the input values from user which will then be stored in the list. I hope that makes it clear.🙂
26th Aug 2020, 2:17 PM
Hamza Rarani
Hamza Rarani - avatar
0
https://code.sololearn.com/cEqzL85FxR1H/?ref=app try like this: first line integer example: 3 then: following three lines a b c
26th Aug 2020, 2:20 PM
Hamza Rarani
Hamza Rarani - avatar
0
Hamza Rarani so can I do some what like this a = input () For I in range(input): X[i] = input()
26th Aug 2020, 2:21 PM
Smiley[Offline]
0
smiley a = int(input()) for i in range(a): x[i]=input() this way u can do it
26th Aug 2020, 2:24 PM
Hamza Rarani
Hamza Rarani - avatar
0
Hamza Rarani sorry sir but your above code is giving error
26th Aug 2020, 2:32 PM
Smiley[Offline]
0
smiley check the code now For EOF error you just have to wrap the code in the try except
26th Aug 2020, 2:36 PM
Hamza Rarani
Hamza Rarani - avatar