您的位置:首页 > 编程语言 > Python开发

高级编程技术 Python 第三周作业

2018-04-02 00:10 573 查看
第五章:if语句
#5-6age = 100
if (age < 2):
print("Infant")
elif (age < 4):
print("Learning Walk")
elif (age < 13):
print("Child")
elif (age < 20):
print("Teenager")
elif (age < 65):
print("Adult")
else:
print("Elderly")#5-7favorite_fruits = ['Cherry', 'Litchi', 'Strauberry', 'Mango']
if ('Apple' in favorite_fruits):
print ('Apple~')
if ('Cherry' in favorite_fruits):
print ('Cherry~')#5-11integers = range(1, 10)
for i in integers:
if (i == 1):
print ('1st')
elif (i == 2):
print ('2nd')
elif (i == 3):
print ('3rd')
else:
print (str(i)+'th')第六章:字典
#6-1owb = {}
owb['first_name'] = 'Weibin'
owb['last_name'] = 'Ou'
owb['age'] = 20
owb['city'] = 'Foshan'
for ikey, ivalue in owb.items():
print(ikey, '=', ivalue)
#6-5country = {}
country['volga'] = 'russia'
country['donube'] = 'austria'
country['seine'] = 'france'

for key, value in country.items():
print ('The '+key.title()+' flows through '+value.title()+'.')
for key, value in country.items():
print (key.title())
for key, value in country.items():
print (value.title())#6-11cities = {
'vienna':{
'country': 'austria',
'population': 1800000,
'fame': 'City of Music',
},
'paris':{
'country': 'france',
'population': 9000000,
'fame': 'City of Fashion',
},
'london':{
'country': 'britain',
'population': 7000000,
'fame': 'City of Finance',
},
}
for city, value in cities.items():
print(city.title()+':')
for key, item in value.items():
if (key == 'country'):
print(' '+key+':', item.title())
else:
print(' '+key+':', item) 这两章的内容充分体现了python语言相对C++更加易于编写,可以省去很多在c++里的麻烦。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: