Python编程作业【第二周】(一)

3-1 names

names = ['zhaobinqi', 'zhuzhiru', 'zongjie']
for name in names:
    print (name)

3-2 greet words

names = ['zhaobinqi', 'zhuzhiru', 'zongjie']
for name in names:
    print (name.title() + ', nice to meet you!')

3-3 my list

vehicles = ['bike', 'car', 'train', 'subway']
for vehicle in vehicles:
    print ("I love taking " + vehicle)

3-4 honored guests

persons = ['father', 'mother', 'zhaobinqi']
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")

3-5 change the list

persons = ['father', 'mother', 'zhaobinqi']
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")
print ("\nSorry to hear that mother can not be in present")
persons.remove("mother")
persons.append("grandpa")
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")

3-6 add new names to the list

persons = ['father', 'mother', 'zhaobinqi']
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")
print ("\nSorry to hear that mother can not be in present")
persons.remove("mother")
persons.append("grandpa")
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")
print ("Glad to say that I've found another bigger table and I would like to invite another three persons")
persons.insert(0, "zongjie")
persons.insert(2, "zhuzhiru")
persons.append("zouyuanhao")
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")

3-7 delete the list

persons = ['father', 'mother', 'zhaobinqi']
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")
print ("\nSorry to hear that mother can not be in present")
persons.remove("mother")
persons.append("grandpa")
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")
print ("Glad to say that I've found another bigger table and I would like to invite another three persons")
persons.insert(0, "zongjie")
persons.insert(2, "zhuzhiru")
persons.append("zouyuanhao")
for person in persons:
    print (person + ", hello! I would like to invite you to eat dinner with me!")
print ("Sorry to say that I could only invite 2 guests to my dinner")
print  ("Sorry, " + persons.pop() + ", I con't invite you.")
print  ("Sorry, " + persons.pop() + ", I con't invite you.")
print  ("Sorry, " + persons.pop() + ", I con't invite you.")
print  ("Sorry, " + persons.pop() + ", I con't invite you.")
for person in persons:
    print (person + ", hello! You are still on the list!")
del persons[0]
del persons[0]
print (persons)

3-8 the world

countries = ["China", "America", "British", "Canada", "France"]
print (countries)
print (sorted(countries))
countries.reverse()
print (countries)
countries.sort()
print (countries)

3-9 length

countries = ["China", "America", "British", "Canada", "France"]
print (len(countries))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值