I’m currently trying to solve the max value problem. However, I’m now having a hard time getting many outputs at the same time. I try to use input().splitlines() to do it, but I only get one output. The test case and output need to have many lines just as the box’s examples. If anyone can provide me with some assistance, I would be very much appreciated it.
JavaScript
x
19
19
1
Example:
2
Input:
3
1,2,3
4
4,5,6
5
7,8,9
6
7
output:
8
3
9
6
10
9
11
12
for line in input().splitlines():
13
14
nums = []
15
for num in line.split(','):
16
nums.append(int(num))
17
print(nums)
18
max(nums)
19
Advertisement
Answer
input
does not handle multiline, you need to loop. You can use iter
with a sentinel to repeat the input and break the loop (here empty line).
JavaScript
1
5
1
nums = []
2
for line in iter(input, ''):
3
nums.append(max(map(int, line.split(','))))
4
print(nums)
5
example:
JavaScript
1
6
1
1,2,3
2
4,5,6
3
7,8,9
4
5
[3, 6, 9]
6
NB. this code does not have any check and works only if you input integers separated by commas