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 ??
11 Respuestas
+ 3
That's a list comprehension.
If you want to figure out how these work, read this:
https://code.sololearn.com/ck6HicJ6Z8jG/?ref=app
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
0
HonFu sorry can't understand pls simplyfy it for me
0
Hamza Rarani sir I was asking that why there is input() before for ?
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.🙂
0
https://code.sololearn.com/cEqzL85FxR1H/?ref=app
try like this:
first line integer example: 3
then:
following three lines
a
b
c
0
Hamza Rarani so can I do some what like this
a = input ()
For I in range(input):
X[i] = input()
0
smiley
a = int(input())
for i in range(a):
x[i]=input()
this way u can do it
0
Hamza Rarani sorry sir but your above code is giving error
0
smiley check the code now
For EOF error you just have to wrap the code in the try except