hw2(第二周)

# [3-1, 3-2, 3-3]
# 3-1
names = ['Mao', 'Deng', 'Jiang', 'Hu', 'Xi']
for name in names:
    print(name)
# 3-2
for name in names:
    print(name + ': Hello!')
# 3-3
vehicles = ['motorcycle', 'bike', 'car']
for vehicle in vehicles:
    print('I would like to own a ' + vehicle)

# [3-4, 3-5, 3-6, 3-7]
# 3-4
names = ['Mao', 'Deng', 'Jiang', 'Hu', 'Xi']
for name in names:
    print(name + ', would you please having a meal with me?')
# 3-5
print('\nOh, ' + names[2] + ' won\'t have time!')
names[2] = 'Wallace'
for name in names:
    print(name + ', would you please having a meal with me?')
# 3-6
print('\nI\'ve found a bigger table. It\'s my pleasure to invite more people.')
names.insert(0, 'Zhu')
names.insert(len(names)//2, 'Li')
names.append('Zhou')
for name in names:
    print(name + ', would you please having a meal with me?')
# 3-7
print('\nOops, sorry, I can only invite two people.')
while len(names) > 2:
    print(names.pop() + ': I\'m sorry to tell you that I can\'t invite you.')
for name in names:
    print(name + ', would you please having a meal with me?')
del(names[0])
del(names[0])
print(names == [] and 'It\'s empty.' or 'It\'s not empty.')


# [3-8, 3-9, 3-10]
# 3-8
places = ['Heaven', 'Hell', 'Well', 'World' ,'SYSU']
print(places)
print(sorted(places))
print('%s\n%s'%(places, (places == ['Heaven', 'Hell', 'Well', 'World' ,'SYSU'] and 'Didn\'t changed' or 'Changed')))
print(sorted(places, reverse=True))
print('%s\n%s'%(places, (places == ['Heaven', 'Hell', 'Well', 'World' ,'SYSU'] and 'Didn\'t changed' or 'Changed')))
places.reverse()
print('%s\n%s'%(places, (places == ['Heaven', 'Hell', 'Well', 'World' ,'SYSU'] and 'Didn\'t changed' or 'Changed')))
places.reverse()
print('%s\n%s'%(places, (places == ['Heaven', 'Hell', 'Well', 'World' ,'SYSU'] and 'Didn\'t changed' or 'Changed')))
places.sort()
print('%s\n%s'%(places, (places == ['Heaven', 'Hell', 'Well', 'World' ,'SYSU'] and 'Didn\'t changed' or 'Changed')))
# 3-9
names = ['Mao', 'Deng', 'Jiang', 'Hu', 'Xi']
print('I would like to invite %d people'%len(names))
# 3-10
myList = ['Membrane', '衆軮', 'はぢはぢ', 233, places]
print(myList)
myList.append(myList)
print(myList)
print(sorted(myList, key=lambda a: False, reverse=True))
myList.reverse()
print(myList)

# [4-1, 4-2]
# 4-1
pizzas = ['A', 'B', 'C']
for pizza in pizzas:
    print(pizza)
for pizza in pizzas:
    print('I like ' + pizza + ' pizza')
print('I really love pizza!')
# 4-2
animals = ['horse', 'donkey', 'lama pacos']
for animal in animals:
    print(animal)
for animal in animals:
    print('A ' + animal + ' walks with four legs')
print('Any of these animals walk with four legs!')

# [4-3, 4-4, 4-5, 4-6, 4-7, 4-8, 4-9]
# 4-3
for i in range(1, 21):
    print(i)
# 4-4
l = range(1, 1000001)
for i in l:
    print(i)
# 4-5
print(min(l))
print(max(l))
print(sum(l))
# 4-6
l2 = [i for i in range(1, 21, 2)]
for i in l2:
    print(i)
# 4-7
l3 = [i for i in range(3, 31, 3)]
for i in l3:
    print(i)
# 4-8
l4 = [i**3 for i in range(1, 11)]
for i in l4:
    print(i)
# 4-9
l5 = [i**3 for i in range(1, 11)]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值