python从入门到精通第三章的课后作业(自己练习)
作业3-1
# names=['rourou','daidai','magua','xialingdang','xiaowangzi','xiaohezi']
# print(names)
# 作业3-2
# for name in names:
# print('Hello,'+name+'!')
# 作业3-3
# traffic_ways=['car','bus','on foot','motorcycle','bike']
# for traffic_way in traffic_ways:
# print('I would like to go to work by '+traffic_way+'.')
# 作业3-4、3-5、3-6、3-7
# names=['yayay','goup','sanfa']
# for name in names:
# print('I want to have dinner with '+name.title())
# print(names[1].title()+' can not come')
# names[1]='sdfej'
# for name in names:
# print('I want to have dinner with '+name.title())
# names.append('wisnf')
# names.insert(2,'miena')
# for name in names:
# print('I want to have dinner with '+name.title())
# a=names.pop()
# print('sorry,'+a+'cannot come')
# b=names.pop()
# print('sorry,'+b+'cannot come')
# c=names.pop()
# print('sorry,'+c+'cannot come')
# for name in names:
# print(name.title()+'can come as promissed')
# del names[0]
# names.remove('sdfej')
# print(names)
# 作业3-8、3-9
# spots=['yunnan','hainan','xiamen','fujian','chengdu']
# print(sorted(spots,reverse=True))
# print(spots)
# spots.reverse()
# print(spots)
# spots.reverse()
# print(spots)
# spots.sort()
# print(spots)
# spots.sort(reverse=True)
# print(spots)
# print(len(spots))
# 作业3-11
# print(spots[-1])