27 lines
734 B
Python
27 lines
734 B
Python
# Exercise 6-5 Rivers
|
|
# Learning Objective: Use a loop on a dictionary using:
|
|
# A.) Both Kay and Value
|
|
# B.) Just Keys
|
|
# C.) Just Values
|
|
|
|
rivers = {'nile': 'egypt', 'mississippi': 'united states', 'volga': 'russia',}
|
|
|
|
# A. Both Key and Value:
|
|
for river, country in rivers.items():
|
|
print(f"\nThe {river.title()} runs through {country.title()}.")
|
|
|
|
print("\n-----------------------------------")
|
|
#B. Just Key:
|
|
|
|
for river in rivers.keys():
|
|
print(f"\nWe have the {river.title()} river in this dictionary.")
|
|
|
|
print("\n-----------------------------------")
|
|
|
|
#C. Just Values:
|
|
|
|
for country in rivers.values():
|
|
print(f"\nWe have the country {country.title()}, in this dictionary.")
|
|
|
|
print("\n-----------------------------------")
|