Python中不同行的输入和输出
我目前正在尝试解决最大值问题。 然而,我现在很难同时获得许多输出。 我尝试使用 input().splitlines() 来执行此操作,但我只得到一个输出。测试用例和输出需要有很多行,就像盒子的示例一样。如果有人能为我提供一些帮助,我将不胜感激。
Example:
Input:
1,2,3
4,5,6
7,8,9
output:
3
6
9
for line in input().splitlines():
nums = []
for num in line.split(','):
nums.append(int(num))
print(nums)
max(nums)
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.
Example:
Input:
1,2,3
4,5,6
7,8,9
output:
3
6
9
for line in input().splitlines():
nums = []
for num in line.split(','):
nums.append(int(num))
print(nums)
max(nums)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
input
不处理多行,您需要循环。您可以将iter
与哨兵一起使用来重复输入并打破循环(此处为空行)。示例:
注意。此代码没有任何检查,仅当您输入以逗号分隔的整数时才有效
input
does not handle multiline, you need to loop. You can useiter
with a sentinel to repeat the input and break the loop (here empty line).example:
NB. this code does not have any check and works only if you input integers separated by commas
你能试试这个吗?
Can you try this out?