【发布时间】:2026-02-26 11:15:01
【问题描述】:
这是我的python文件:-
TestCases-2
Input-5
Output-1,1,2,3,5
Input-7
Ouput-1,1,2,3,5,8,13
我想要的是这个:-
- 变量
test_no = 2(测试用例数) - 列表
testCaseInput = [5,7] - 列表
testCaseOutput = [[1,1,2,3,5],[1,1,2,3,5,8,13]]
我尝试过这样做:
testInput = testCase.readline(-10)
for i in range(0,int(testInput)):
testCaseInput = testCase.readline(-6)
testCaseOutput = testCase.readline(-7)
下一步是在(',') 的基础上去除数字,然后将它们放入一个列表中。
奇怪的是,readline(-6) 没有给出预期的结果。
有没有更好的方法来做到这一点,显然我错过了。
我不介意在这里使用序列化,但我想让某人像我展示的那样编写一个文本文件然后从中取出数据变得非常简单。该怎么做?
【问题讨论】:
-
您期待什么结果,您认为 .
readline()方法的负参数到底应该做什么? -
我期望 readline(-6) 它做的,或者它正在做的是跳到行的第 6 个字符,然后从那里存储到行尾'\n' 结尾。