第三章作业

3-1
names = ['Joker','James','Key']
print(names[0])
print(names[1])
print(names[2])

3-2

names = ['Joker','James','Key']
for name in names:
	print('Hello, '+name)
3-3
vehicles = ['car','bike','boat','plane']
for vehicle in vehicles:
	print('I would like to own a '+vehicle+'.')

3-4

guests = ['Father','Mother','sister']
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')

3-5

guests = ['Father','Mother','sister']
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
print('Father can\'t come.')
guests[0] = 'brother'
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')

3-6

guests = ['Father','Mother','sister']
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
print('Father can\'t come.')
guests[0] = 'brother'
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
print('I have found a bigger table.')
guests.insert(0,'John')
guests.insert(2,'Key')
guests.append('Amy')
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')

3-7

guests = ['Father','Mother','sister']
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
print('Father can\'t come.')
guests[0] = 'brother'
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
print('I have found a bigger table.')
guests.insert(0,'John')
guests.insert(2,'Key')
guests.append('Amy')
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
print('I\'m sorry, but I can only invite two people for dinner now.')
print(guests.pop()+', I\'m sorry to tell you I can\'t invite you now.')
print(guests.pop()+', I\'m sorry to tell you I can\'t invite you now.')
print(guests.pop()+', I\'m sorry to tell you I can\'t invite you now.')
print(guests.pop()+', I\'m sorry to tell you I can\'t invite you now.')
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
del guests[0]
del guests[0]
print(guests)

3-8

places = ['Japan','Beijing','Hongkong','America','Australia']
print(places)
print(sorted(places))
print(places)
print(sorted(places,reverse=True))
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse=True)
print(places)

3-9

guests = ['Father','Mother','sister']
for guest in guests:
	print('Please come and have dinner with me tonight, '+guest+'.')
print('I have invited '+str(len(guests))+' guests.')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值