Python编程 从入门到实践 第三章 作业参考答案

3-1 3-2 姓名 问候语

names = ["书涵","剑权","泽坤"]

sayhi = ",你好呀~~"

for name in names:
    print(name)

print('----------')

for name in names:
    print(name,sayhi)
================= RESTART: D:/program/Python/print_names.py =================
书涵
剑权
泽坤
----------
书涵 ,你好呀~~
剑权 ,你好呀~~
泽坤 ,你好呀~~

3-3 自己的列表

transportation =[ "on foot","by Honda motorcycle",
                  "by bike", "by Xiaohuang"]

for t in transportation:
    print("Well, today I want to go outside",t)
================= RESTART: D:/program/Python/print_names.py =================
Well, today I want to go outside on foot
Well, today I want to go outside by Honda motorcycle
Well, today I want to go outside by bike
Well, today I want to go outside by Xiaohuang

3-4  3-5 3-6 3-7 嘉宾名单 修改嘉宾名单 添加嘉宾名单 缩减名单

invitation = ["Hawking","Turning","Knuth"]

def invite():
    for one in invitation:
        print("Hi,{},could you please go dinner with me tonight?".format(one))

invite() #3-4

deny = invitation[0]
print("{} has just left us".format(deny))

invitation[0] = "Zhengning Wang"
invite() #3-5

print("Good news. We have found a greater table.")
invitation.insert(0,"Zhengdao Li")
invitation.insert(2,"Xingbei Shu")
invitation.append("Jiuzhang Zhao")

invite() # 3-6
print("I'm very sorry that I cannot invite all of you\
, due to the new table's delivery.")

for one in invitation[2:]:
    print(one,",I'm very sorry that I cannot invite all of you\
, due to the new table's delivery.\n")
    invitation.pop(2)

for one in invitation[:2]:
    print(one,", you are still invited. Can you come over?")

del invitation[0]
del invitation[0]
invite()
================= RESTART: D:/program/Python/print_names.py =================
Hi,Hawking,could you please go dinner with me tonight?
Hi,Turning,could you please go dinner with me tonight?
Hi,Knuth,could you please go dinner with me tonight?
Hawking has just left us
Hi,Zhengning Wang,could you please go dinner with me tonight?
Hi,Turning,could you please go dinner with me tonight?
Hi,Knuth,could you please go dinner with me tonight?
Good news. We have found a greater table.
Hi,Zhengdao Li,could you please go dinner with me tonight?
Hi,Zhengning Wang,could you please go dinner with me tonight?
Hi,Xingbei Shu,could you please go dinner with me tonight?
Hi,Turning,could you please go dinner with me tonight?
Hi,Knuth,could you please go dinner with me tonight?
Hi,Jiuzhang Zhao,could you please go dinner with me tonight?
I'm very sorry that I cannot invite all of you, due to the new table's delivery.
Xingbei Shu ,I'm very sorry that I cannot invite all of you, due to the new table's delivery.

Turning ,I'm very sorry that I cannot invite all of you, due to the new table's delivery.

Knuth ,I'm very sorry that I cannot invite all of you, due to the new table's delivery.

Jiuzhang Zhao ,I'm very sorry that I cannot invite all of you, due to the new table's delivery.

Zhengdao Li , you are still invited. Can you come over?
Zhengning Wang , you are still invited. Can you come over?

3-8 放眼世界

places = ['Paris','New York','San Fransico','London','Silcon Valley']

print("--------------------------")
print(places)
print("--------------------------")
print(sorted(places))
print("--------------------------")
print(places)
print("--------------------------")
print(sorted(places,reverse=True))
print("--------------------------")
print(places)
print("--------------------------")
places.reverse()
print(places)
print("--------------------------")
places.reverse()
print(places)
print("--------------------------")
places.sort()
print(places)
print("--------------------------")
places.sort(reverse=True)
print(places)
=============== RESTART: D:/program/Python/place_want_to_go.py ===============
--------------------------
['Paris', 'New York', 'San Fransico', 'London', 'Silcon Valley']
--------------------------
['London', 'New York', 'Paris', 'San Fransico', 'Silcon Valley']
--------------------------
['Paris', 'New York', 'San Fransico', 'London', 'Silcon Valley']
--------------------------
['Silcon Valley', 'San Fransico', 'Paris', 'New York', 'London']
--------------------------
['Paris', 'New York', 'San Fransico', 'London', 'Silcon Valley']
--------------------------
['Silcon Valley', 'London', 'San Fransico', 'New York', 'Paris']
--------------------------
['Paris', 'New York', 'San Fransico', 'London', 'Silcon Valley']
--------------------------
['London', 'New York', 'Paris', 'San Fransico', 'Silcon Valley']
--------------------------
['Silcon Valley', 'San Fransico', 'Paris', 'New York', 'London']

太多啦,不打了。

有任何疑问请 email [email protected] 寻求帮助


你可能感兴趣的:(Python学习,Python作业,Python学习,Python作业,Python作业)