python编程从入门到实践第三章习题答案

本文通过几个简单的Python代码示例介绍了如何使用for循环进行基本的操作,包括打印名字列表、更新并通知名单变化、以及列表排序等操作。这些例子有助于初学者理解Python的基本语法和列表操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3.1-3.2
names = ['zhichao' , 'yujie' , 'yifei']

for name in names:
    print( name.title() + " , good night.")
3.3
transportation = ['car' , 'walk', 'bicycle' , 'motorcycle']

for elem in transportation :
    print( "I would like to own a Honda motorcycle " + elem )
3.4-3.7
#3.4部分
people = ['宙斯' , '赫拉' , '雅典娜' , '阿芙洛蒂忒' ]
for person in people :     print( person + " , I want to have a dinner with you." )
#3.5部分 unable = '宙斯' new_one = '海伦' print( unable + " can't participate in." ) print ( 20 * "*")unable = '宙斯' new_one = '海伦' people.remove( unable )#3.6部分 people.append( new_one ) people.insert( 0,'阿波罗') people.insert( 3,'阿瑞斯' ) for person in people :     print( person + " , I want to have a dinner with you." )
print ( 20 * "*")
#3.7部分
while len( people ) > 2 :     people.pop() for person in people :     print( person + " , I want to have a dinner with you." )
i = len(people) -1 while i > 0 :     del people[i] i = len( people )-1



3.8
place = ['England' , "Greece" , 'America' , 'France']
print( place )

print( sorted( place ) )
print( place )

print( sorted( place , reverse = True ) )
print( place )

place.reverse()
print( place )

place.reverse()
print( place )

place.sort()
print( place )

place.sort( reverse = True )
print( place )

3.9
这个已经在3.4-3.7的代码块中展示过

3.10-3.11


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值