number_of_testcases = input()
number_of_girls = int(input().split())
i=0
a = []
b = []
while i < number_of_girls:
v,n = input().split()
a.append(v)
b.append(n)
i = i +1
I am trying to get the first line of each test case contains an integer n
and it is followed by n
lines, each containing two space-separated integers.
The error I am getting is
v,n = input().split()
EOFError: EOF when reading a line'
Can someone please explain? I am new to python and it is hard to understand.
Guessing from your error message: you seem to have not enough data to parse available. But your code should give you an even earlier error:
Because int()
can operate on a string containing a single number - not on a list that contains multiple strings.
Use
number_of_girls = list(map(int,input().split()))
instead - you'll get a list of ints or it crashes if you input non-numbers.
Generally to do what you aim for I would do:
data = []
cases = int(input().strip()) # number of cases in a single line
for _ in cases:
girls = int(input().strip()) # number of girs per test case given in single line
case = [[],[]]
for _ in range(girls):
a,b = map(int,input().strip().split()) # 2 numbers space seperated in single line
case[0].append(a)
case[1].append(b)
data.append(case)
to get all data for all test cases.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.