W3-C2 作业

6-1

person={
	"first_name":"Yuan",
	"last_name":"Fang",
	"city":"Guangzhou",
	"age":20,
	}
print(person)


6-2
friends={
	"Fang Yuan":19980114,
	"Zhang Tongrui":19980713,
	"Wang Zeyuan":19980715,
	"Zhao Minglai":19981001,
	}
for friend in friends.keys():
	print("Dear "+friend+" ,is your favorite number "+str(friends[friend])+" ?")



6-3
dictionary={
	"Fang":"family name",
	"Yuan":"first name",
	"month":1,
	"day":14,
	"year":1998
	}
for source in dictionary.keys():
	print(source+" : "+str(dictionary[source]))


6-4
dictionary={
	"Fang":"family name",
	"Yuan":"first name",
	"month":1,
	"day":14,
	"year":1998,
	}
for source,definition in dictionary.items():
	print(source+" : "+str(definition))
dictionary["Zhang"]="family name"
dictionary["Tongrui"]="first name"
dictionary["month_2"]=7
dictionary["day_2"]=13
dictionary["year_2"]=1998
for source,definition in dictionary.items():
	print(source+" : "+str(definition))

先写到这,困了,明天继续。。。。。。

更新:

6-5

cities={
	"Beijing":"China",
	"Paris":"France",
	"Washington":"USA",
	}
for city,country in cities.items():
	print(city+" is in "+country+".")
for city in cities.keys():
	print(city)
for country in cities.values():
	print(country)

6-6
favorite_languages={
	"jen":"python",
	"sarah":"c",
	"edward":"ruby",
	"phil":"python",
	}
people=["lily","sarah","phil","cindy","tom"]
for person in people:
	if person in favorite_languages.keys():
		print("Thank you!")
	else:
		print("Please take the test!")


6-7

person_1={
	"first_name":"Yuan",
	"last_name":"Fang",
	"city":"Guangzhou",
	"age":20,
	}
person_2={
	"first_name":"Tongrui",
	"last_name":"Zhang",
	"city":"Guangzhou",
	"age":19,
	}
person_3={
	"first_name":"Zeyuan",
	"last_name":"Wang",
	"city":"Beijing",
	"age":19,
	}
people=[person_1,person_2,person_3]
for person in people:
	print(person)

6-8
FY={
	"type":"dog",
	"owner":"Cody"
	}
Lily={
	"type":"cat",
	"owner":"Cindy"
	}
Sandy={
	"type":"rabbit",
	"owner":"Tom"
	}
pets=[FY,Lily,Sandy]
print(pets)


6-9
favorite_places={
	"Fang Yuan":["Paris","Chengdu"],
	"Zhang Tongrui":["Paris","Beijing"],
	"Wang Zeyuan":["Jilin"],
	}
for person,places in favorite_places.items():
	print(person,end=":")
	print(places)

6-10
friends={
	"Fang Yuan":[1998,1,14],
	"Zhang Tongrui":[1998,7,13],
	"Wang Zeyuan":[1998,7,15],
	"Zhao Minglai":[1998,10,1],
	}
for friend,information in friends.items():
	print(friend,end=":")
	print(information)

6-11

cities={
	"Beijing":{
		"country":"China",
		"population":"a lot",
		},
	"Pairs":{
		"country":"France",
		"population":"quite a few",
		},
	"Changchun":{
		"country":"China",
		"population":"not that much",
		},
	}
for city,information in cities.items():
	print(city,end=":")
	print(information)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值