【Python 3.7】河流:创建一个字典,在其中存储三条大河流及其流经的国家。其中一个键 — 值对可能是 ‘nile’: ‘egypt’ 。
题目:河流:创建一个字典,在其中存储三条大河流及其流经的国家。其中一个键 —值对可能是 ‘nile’: ‘egypt’ 。
使用循环为每条河流打印一条消息,如“The Nile runs through Egypt.”。
使用循环将该字典中每条河流的名字都打印出来。
使用循环将该字典包含的每个国家的名字都打印出来
程序为:
rivers={'nile':'egypt','Yangtze river':'china','Yellow river':'china'}
for river,conutry in rivers.items():
print("The "+river.title()+" runs through "+conutry.title())
for river in rivers.keys():
print(river.title())
for conutry in set(rivers.values()):
print(conutry.title())
结果为:
The Nile runs through Egypt
The Yangtze River runs through China
The Yellow River runs through China
Nile
Yangtze River
Yellow River
Egypt
China
博客围绕 Python 3.7 展开,给出一个字典习题,要求创建字典存储三条大河流及其流经国家,如 'nile': 'egypt' ,并通过循环分别打印关于河流的消息、河流名字和国家名字。
1101

被折叠的 条评论
为什么被折叠?



