第六次作业(2018-03-21,周三)

6-1

inf = {"first_name":"Huan", "last_name":"Huang", "age":20, "city":"GuangZhou"}
print("first_name:"+inf["first_name"])
print("last_name:"+inf["last_name"])
print("age:",end = "")
print(inf["age"])

print("city:"+inf["city"])

6-3

vocabulary = {}
vocabulary["variable"] = "a quanlity that can assume any of a set of values"
vocabulary["string"] = "suquence of symbols or digits in computer programing"
vocabulary["annotation"] = "a comment or instruction(usually added)"
vocabulary["list"] = "a database containing an ordered array of items(names or topics)"
vocabulary["tuple"] = "an ordered list of elements"
print("variable:"+vocabulary["variable"])
print("string:"+vocabulary["string"])
print("annotation:"+vocabulary["annotation"])
print("list:"+vocabulary["list"])

print("tuple"+vocabulary["tuple"])

6-4

vocabulary = {}
vocabulary["variable"] = "a quanlity that can assume any of a set of values"
vocabulary["string"] = "suquence of symbols or digits in computer programing"
vocabulary["annotation"] = "a comment or instruction(usually added)"
vocabulary["list"] = "a database containing an ordered array of items(names or topics)"
vocabulary["tuple"] = "an ordered list of elements"
#print("variable:"+vocabulary["variable"])
#print("string:"+vocabulary["string"])
#print("annotation:"+vocabulary["annotation"])
#print("list:"+vocabulary["list"])
#print("tuple"+vocabulary["tuple"])
for voc,exp in vocabulary.items():

print(voc+":"+exp)

6-5

river = {"Long River":"China", "Yellow River":"China", "Nile":"Egypt"}
for riv,coun in river.items():
print("The "+riv+" runs through "+coun+".")
for riv in river.values():
print(riv)
for coun in river.keys():

print(coun)

6-6

favorite_language = {"jen":'python',"sarah":'c', "edwrad":'ruby', 'phil':'python'}
list = []
for name in favorite_language.keys():
if favorite_language[name]=='python':
list.append(name)
for name in list:
print("Thank you for your participation, "+name+".")
for name in favorite_language.keys():
if name not in list:

print("Would you like to participate in our investigation?"+name+".")

6-7

people = [{"first_name":"Huan", "last_name":"Huang", "age":20, "city":"GuangZhou"}, {"first_name":"Tao", "last_name":"Huang", "age":17, "city":"GanZhou"}, {"first_name":"JiaYi", "last_name":"Huang", "age":15, "city":"GanZhou"}]
for inf in people:
print("first_name:"+inf["first_name"])
print("last_name:"+inf["last_name"])
print("age:",end = "")
print(inf["age"])

print("city:"+inf["city"])

6-8

favorite_places = {"hhh":["GuangZhou","GanZhou", "BeiJing"],"hwt":["ShangHai", "ShenZhen", "HongKong"],"hjy":["NanChang", "ChengDu", "WuHan"]}
for name in favorite_places.keys():
print(name+"'s favorite_places: ",end = "")
for place in favorite_places[name]:
print(place+" ",end= "")

print("\n")


猜你喜欢

转载自blog.csdn.net/baidu_41300735/article/details/79644591