Python第六章课后作业

6-1人:

inf={'first_name':'Ke','last_name':'sibo','age':21,'city':'Guangzhou'}
for mes1,mes2 in inf.items():
	print(mes1+':',mes2)

运行结果:

Python第六章课后作业_第1张图片

6-2喜欢的数字:

number={'ksb':8,'lmd':7,'hyk':2,'kq':1,'lrp':5}
for name,num in number.items():
	print(name,num)

运行结果:

Python第六章课后作业_第2张图片

6-3词汇表:

word={'int':'integer','float':'floating','for':'circulation','del':'delete','sort':'sorting'}
for name,mean in word.items():
	print(name,':',mean)

运行结果:

Python第六章课后作业_第3张图片

6-4词汇表2:

word={'int':'integer','float':'floating','for':'circulation','del':'delete','sort':'sorting','not':'negative','in':'included in','append':'add to the end','pop':'pop out','-1':'the last element'}
for name,mean in word.items():
	print(name,':',mean)

运行结果:

Python第六章课后作业_第4张图片

6-5河流:

river={'nile':'egypt','Yangtze River':'china','congo river':'congo'}
for name,country in river.items():
	print(name+' runs through '+country)
for name in river.keys():
	print(name.title())
for country in river.values():
	print(country.title())

运行结果:

Python第六章课后作业_第5张图片

6-6调查:

favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
arr=['jen','edward','ksb']
for name in arr:
	if name in favorite_languages.keys():
		print('Thank you',name)
	else:
		print(name,"Welcome to our survey")

运行结果:

Python第六章课后作业_第6张图片

6-7人:

man1={'first_name':'Ke','last_name':'sibo','age':21,'city':'Guangzhou'}
man2={'first_name':'Lao','last_name':'madong','age':20,'city':'Guangzhou'}
man3={'first_name':'Huang','last_name':'yikai','age':20,'city':'Guangzhou'}
arr=[man1,man2,man3]
for inf in arr:
	print(inf)

运行结果:

Python第六章课后作业_第7张图片

6-8宠物:

cat={'color':'yellow','master':'ksb'}
dog={'color':'black','master':'lmd'}
fish={'color':'orange','master':'hyk'}
pets=[cat,dog,fish]
for pet in pets:
	print(pet)

运行结果:

Python第六章课后作业_第8张图片

6-9喜欢的地方:

ksb=['china']
lmd=['american']
kq=['canada','china']
favorite_places={'ksb':ksb,'lmd':lmd,'kq':kq}
for name,place in favorite_places.items():
	print(name+':',place)

运行结果:

Python第六章课后作业_第9张图片

6-10喜欢的数字:

ksb=[8,2,6]
lmd=[7,2,1]
hyk=[1,8,6,0]
kq=[0]
lrp=[1,5,9,0]
number={'ksb':ksb,'lmd':lmd,'hyk':hyk,'kq':kq,'lrp':lrp}
for name,num in number.items():
	print(name,end=' ')
	for n in num:
		print(n,end=' ')
	print()

运行结果:

Python第六章课后作业_第10张图片

6-11城市:

cities={
	'Guangzhou':{'country':'China','population':'14million','fact':'nice'},
	'Shenzhen':{'country':'China','population':'12million','fact':'beautiful'},
	'Beijing':{'country':'China','population':'21million','fact':'cold'}
}
for city,inf in cities.items():
	print(city)
	for i,j in inf.items():
		print(i+':',j)

运行结果:

Python第六章课后作业_第11张图片

6-12扩展:略


你可能感兴趣的:(python作业)