python作业 第二周

第三章作业

#3-1
names = ['pp', 'ydm', 'wzy', 'cx']
for name in names:
    print(name)
#3-2
for name in names:
    print(name, 'f**k you')
#3-3
transportation = ['automobile', 'subway', 'bicycle', 'foot']
print('I own one', transportation[0])
print('I prefer taking', transportation[1], 'to travel around the cith')
print('I am able to ride a', transportation[2], 'to my classroom')
print('I usually go to school on', transportation[3])
#3-4
for name in names:
    print('come here and eat a big meal together,', name)
#3-5
print(names[0], 'is busy with study and can not come to the dinner')
del names[0]
for name in names:
    print('come here and eat a big meal together,', name)
#3-6
print('I am really rich and have got a big table for you guys')
names.insert(0, 'pp')
names.insert(2, 'zyc')
names.append('zxy')
for name in names:
    print('come here and eat a big meal together,', name)
#3-7
print('Bazinga! Only two guys will be invited')
while len(names) > 2:
    print(names.pop(), 'out!')
for name in names:
    print(name + ', you got it!')
while names:
    names.pop()
print(names)
#3-8
places = ['Shenzhen', 'Newyork', 'Tokyo', 'Paris', 'Taiwan']
print(places)
print(sorted(places))
print(sorted(places, reverse = True))
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse = True)
print(places)
#3-9
print('the number of total invited members:',len(names))
#3-11
print('length of names:', len(names))
#for i in range(1, 10):  越界
    #print(names[i])
for i in range(0, 10):
    names.append(i)

for i in range(1, 10):  
    print(names[i])

第四章作业

#4-1
pizzas = ['cheese', 'sausage', 'chicken']
for pizza in pizzas:
    print('I like', pizza, 'pizza')
print('''I really don't like pizza''')
#4-2
animals = ['puppy', 'kitty', 'eagle', 'pig']
for animal in animals:
    print(animal, 'can be a great and lovely pet')
print('All of these animals can be a pet for us')
#4-3
for num in range(1, 21):
    print(num)
#4-4
million = list(range(1, 1000001))
#for m in million:
#   print(m)
#4-5
#print(sum(million))
#4-6
odds = list(range(1, 20, 2))
for odd in odds:
    print(odd)
#4-7
three = [i for i in range(3, 31) if i % 3 == 0]
for t in three:
    print(t)
#4-8
cube = [i ** 3 for i in range(1, 11)]
for c in cube:
    print(c)
#4-9
cube = [i ** 3 for i in range(1, 11)]
#4-10
print('The first three items in the list are:')
for i in cube[:3]:
    print(i)

print('Three items from the middle of the list are:')
for i in cube[2:5]:
    print(i)

print('The last three items in the list are:')
for i in cube[-3:]:
    print(i)
#4-13
foods = ('pork', 'beef', 'chicken', 'bread', 'shit')
for food in foods:
    print(food)
#foods[0] = 'milk'
foods = ('milk', 'vegetable', 'chicken', 'bread', 'shit')
for food in foods:
    print(food)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值