Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7110008

Browse files
committed
Add Chapter 11.5 exercise solutions
1 parent9dcee98 commit7110008

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

‎ch11-file-input-and-output/5-challenge-create-a-high-scores-list-from-csv-data.py

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 11.5 - Reading and Writing Files
2+
# Solutions to Exercises
3+
4+
5+
# Exercise 1
6+
frompathlibimportPath
7+
8+
starships= ["Discovery\n","Enterprise\n","Defiant\n","Voyager"]
9+
10+
file_path=Path.home()/"starships.txt"
11+
withfile_path.open(mode="w",encoding="utf-8")asfile:
12+
file.writelines(starships)
13+
14+
15+
# Exercise 2
16+
withfile_path.open(mode="r",encoding="utf-8")asfile:
17+
forstarshipinfile.readlines():
18+
print(starship,end="")
19+
20+
21+
# Exercise 3
22+
withfile_path.open(mode="r",encoding="utf-8")asfile:
23+
forstarshipinfile.readlines():
24+
ifstarship.startswith("D"):
25+
print(starship,end="")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp