6-1 人 :使用一个字典来存储一个熟人的信息,包括名、姓、年龄和居住的城市。该字典应包含键first_name 、last_name 、age 和city 。将存储在该字典中的每项信息都打印出来。
friend={
"first_name":"LeBron",
"last_name":"James",
"age":"34",
"city":"Cleveland"
}
for key,value in friend.items():
print(key+':'+value)
"""
output:
first_name:LeBron
last_name:James
age:34
city:Cleveland
"""
6-2 喜欢的数字 :使用一个字典来存储一些人喜欢的数字。请想出5个人的名字,并将这些名字用作字典中的键;想出每个人喜欢的一个数字,并将这些数字作为值存
储在字典中。打印每个人的名字和喜欢的数字。为让这个程序更有趣,通过询问朋友确保数据是真实的。
number={
"Alice":35,
"Bob":7,
"Cindy":22,
"Danny":50,
"Tony":75,
}
for key,value in number.items():
print("The favorite number of "+key+" is "+str(value))
"""
output:
The favorite number of Alic