3.14python作业

这篇博客展示了Python编程中的几个基本操作,包括使用for循环遍历列表打印元素,计算列表最大值、最小值及总和,列表推导式生成立方数列表,以及切片操作显示列表的部分元素。此外,还演示了如何修改列表元素和重新定义列表。

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

# 4-2
animals = ['cat', 'dog', 'tiger']
for animal in animals:
    print(animal)

for animal in animals:
    print('A ' + animal + ' would make a great pet')

print('Any of these animals has a mouth!')



# 4-3
nums = list(range(1,21))
print(nums)
# 4-4
nums1 = list(range(1,1000001))
print(nums1)
# 4-5
print(min(nums1))
print(max(nums1))
aaa = sum(nums1)
print(aaa)


# 4-9
list = [value**3 for value in range(1,11)]
print(list)


# 4-10
print("The first three items in the list are:")
for num in nums[:3]:
    print(num)

print("The last three items in the list are:")
for num in nums[-3:]:
    print(num)


# 4-13
foods = ('fish', 'beef', 'mutton', 'vegetable', 'pork')
for food in foods:
    print(food)
# foods[0] = 'apple'

foods = ('apple', 'beef', 'mutton', 'banana', 'pork')
for food in foods:
    print(food)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值