python编程:从入门到实践-第三章练习

#16337256 肖鉴哲

#3-1
names = [ 'xiaojz' , 'yangxh' , 'yangxy' , 'caobb' ]
for i in names:
print (i)
#3-2
message = 'hi ,'
for i in names:
print (message + i + '!' )
#3-3
method = [ 'car' , 'train' , 'airplane' , 'foot' ]
for i in method:
print ( 'i would like to travel by' ,i)

#3-4
my_guest = [ 'spider-man' , 'punisher' , 'superman' , 'batman' ]
for i in my_guest:
print ( 'can you have dinner with me ,' ,i, '?' )
#3-5
ab_guest = 'batman'
print (ab_guest + ' can \' t come !' )
my_guest.remove(ab_guest)
my_guest.insert( 1 , 'moonknight' )
for i in my_guest:
print ( 'can you have dinner with me ,' ,i, '?' )

#3-6
print ( 'i have found a bigger table !' )
my_guest.insert( 0 , 'Venom' )
my_guest.insert( 2 , 'Iron Fist' )
my_guest.append( 'captain american' )
for i in my_guest:
print ( 'can you have dinner with me ,' ,i, '?' )

#3-7
print ( 'i can only invite 2 people' )
while len (my_guest) > 2 :
i = my_guest.pop()
print ( 'i am so sorry' ,i)


#3-8
myPlace = [ 'beijing' , 'newYork' , 'liyue' , 'shanghai' , 'lundun' ]
print (myPlace)
print ( sorted (myPlace))
print (myPlace)
print ( sorted (myPlace, reverse = True ))
print (myPlace)
myPlace.reverse()
print (myPlace)
myPlace.reverse()
print (myPlace)
myPlace.sort()
print (myPlace)
myPlace.sort( reverse = True )
print (myPlace)

#3-9
print ( 'i invite' , len (my_guest), 'guest' )

#3-11
#my_guest[len(my_guest)]='error'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值