Python第六章課後作業

6-1人:

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

運行結果:


6-2喜歡的數字:

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

運行結果:


6-3詞彙表:

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

運行結果:


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)

運行結果:


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())

運行結果:


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")

運行結果:


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)

運行結果:


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)

運行結果:


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)

運行結果:


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()

運行結果:


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)

運行結果:


6-12擴展:略


發佈了33 篇原創文章 · 獲贊 0 · 訪問量 9013
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章