Python从入门到实践编程题答案(第三章)

3-1

names=["张三","李四","王五"]
print(names[0])
print(names[1])
print(names[2])

3-2


names=["张三","李四","王五"]
for a in names:
    print(a+" 早上好!")

3-3

ways=["walk","bus","boat"]
for item in ways:
    print("I would like to go to school by "+item)

3-4

names=["张三","李四","王五"]
for person in names:
    print( person+", would you like to come to\
my home and have a dinner with me?")
print(names[0]+"can't attend this dinner")

3-5

print(names[0]+" can't attend this dinner")
names[0]="小明"
for person in names:
    print( person+", would you like to come to\
my home and have a dinner with me?")

3-6

print("I find a big table ,so I want to invite more friends")
names.insert(0,"小华")
names.insert(2,"小张")
names.append("小刘")
for person in names:
    print( person+", would you like to come to\
my home and have a dinner with me?")

3-7

print("I can only invite two people to my home because\
 the big table cant send my house in time")
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
popped_name=names.pop()
print(popped_name+"I'm very sorry about that")
print(names)
for person in names:
    print(person+" you can come to my house and have a dinner with me ")
del names[1]
del names[0]
print(names)

3-8

cities=["ShangHai","Beijing","ChengDu","TianJin","HuNan"]
print(cities)
print(sorted(cities))
print(cities)
#sorted(reverse=True)没成功
cities.reverse()
print(cities)
cities.reverse()
print(cities)
cities.sort()
print(cities)
cities.sort(reverse=True)
print(cities)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值