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

Commit d683ca9

Browse files
authored
Add old exercise from 2023年8月21日
1 parent 59e6688 commit d683ca9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎long_rivers.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
rivers = [
2+
{"name": "Nile", "length": 4157},
3+
{"name": "Yangtze", "length": 3434},
4+
{"name": "Murray-Darling", "length": 2310},
5+
{"name": "Volga", "length": 2290},
6+
{"name": "Mississippi", "length": 2540},
7+
{"name": "Amazon", "length": 3915}
8+
]
9+
10+
# 1. In a for loop, print out each river's name!
11+
for i in rivers:
12+
print(i["name"])
13+
total_length = 0
14+
15+
# 2. In another for loop, add up and print out the total length of all the rivers!
16+
for i in rivers:
17+
total_length += i["length"]
18+
print(total_length)
19+
20+
# 1. Print out every river's name that begins with the letter M !
21+
for i in rivers:
22+
if i["name"][0] == "M":
23+
print(i["name"])
24+
25+
# 2. The length of the rivers are in miles. Print out every river's length in kilometres! (1 mile is
26+
# roughly 1.6 km)
27+
for i in rivers:
28+
print(i["length"]*1.6)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /