回答編集履歴
2
Fix answer
test
CHANGED
@@ -28,22 +28,6 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
test.txt:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
```text
|
36
|
-
|
37
|
-
1行目
|
38
|
-
|
39
|
-
2行目
|
40
|
-
|
41
|
-
3行目
|
42
|
-
|
43
|
-
```
|
44
|
-
|
45
|
-
|
46
|
-
|
47
31
|
実行結果:
|
48
32
|
|
49
33
|
|
1
Update answer
test
CHANGED
@@ -4,21 +4,23 @@
|
|
4
4
|
|
5
5
|
```python
|
6
6
|
|
7
|
-
def read_by_line_number(
|
7
|
+
def read_by_line_number(string, line_number):
|
8
8
|
|
9
|
-
with open(path_to_file) as fp:
|
10
|
-
|
11
|
-
|
9
|
+
return s.splitlines()[line_number - 1]
|
12
|
-
|
13
|
-
if i == number - 1:
|
14
|
-
|
15
|
-
return line
|
16
|
-
|
17
|
-
raise Exception()
|
18
10
|
|
19
11
|
|
20
12
|
|
13
|
+
|
14
|
+
|
15
|
+
s = """1行目
|
16
|
+
|
17
|
+
2行目
|
18
|
+
|
19
|
+
3行目"""
|
20
|
+
|
21
|
+
|
22
|
+
|
21
|
-
line = read_by_line_number(
|
23
|
+
line = read_by_line_number(s, 2)
|
22
24
|
|
23
25
|
print(line)
|
24
26
|
|