File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments