高级编程技术 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++里的麻烦。
#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++里的麻烦。
相关文章推荐
- 马哥2016全新Linux+Python高端运维班第三周作业
- [python作业] [第三周] [周一]
- 《高级编程技术》作业[1]——python实现程序构想
- 马哥2016全新Linux+Python高端运维班第三周作业
- 马哥2016全新Linux+Python高端运维班第三周作业
- 第三周作业(1)——高级编程技术
- 高级编程技术(Python)作业10
- [python作业] [第三周] [周三]
- 高级编程技术第三周平时作业
- python第三周作业——chapter 5:if语句,chapter 6:字典
- 高级编程技术(Python)作业5
- 高级编程技术(Python)作业3
- 【高级编程技术】第三周作业
- 马哥2016全新Linux+Python高端运维班第三周作业
- 高级编程技术第三周平时作业(2)
- 高级编程技术(Python)作业6
- 高级编程技术 第三周作业
- 马哥2016全新Linux+Python高端运维班第三周作业
- Python第三周第二次作业
- 高级编程技术 Python 第二周作业