第三章作业

"""3.1 姓名"""
names = ['Niki', 'Bob', 'Anddy']
for item in names:
print(item)

"""3.2 问候语"""
names = ['Niki', 'Bob', 'Anddy']
for item in names:
print(item + ", how are you?")

"""3.3 自己的列表"""
transports = ['motorcycle', 'bus', 'car', 'plane', 'rocket']
for item in transports:
print("I woould like to own a " + item + ".")

"""3.4 嘉宾名单"""
names = ['Einstein','Plonk','Huangdi']
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")


"""3.5 修改嘉宾名单"""
names = ['Einstein','Plonk','Huangdi']
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")
print("Sorry, " + names[1] + " do not have time in the evening.")
names[1] = 'Caesar'
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")


"""3.6 添加嘉宾"""
names = ['Einstein','Plonk','Huangdi']
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")
print("Sorry, " + names[1] + " do not have time in the evening.")
names[1] = 'Caesar'
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")
print("I find a more big table")
names.insert(0, 'Qin Shihuang')
names.insert(0, 'Li Bai')
names.append('Han Xin')
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")


"""3.7 缩减名单"""
names = ['Einstein','Plonk','Huangdi']
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")
print("Sorry, " + names[1] + " do not have time in the evening.")
names[1] = 'Caesar'
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")
print("I find a more big table")
names.insert(0, 'Qin Shihuang')
names.insert(0, 'Li Bai')
names.append('Han Xin')
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")
print("Because the new table can not arrive on time, I can just invite two person to have a dinner together.")
for item in names[2:6]:
names.pop()
print(item + ", I am so sorry that I can not have dinner with you.")
for item in names:
print("Hello, " + item + ", I still would like to invite you to have a dinner with me.")
del names[0]
del names[0]
print(names)


"""3.8 放眼世界"""
places = ['Paris', 'Shanghai', 'Rome', 'New York', 'Maldives']
print(places)
print(sorted(places))
print(places)
print(sorted(places, reverse = True))
print(places)
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse = True)
print(places)


"""3.9 晚餐嘉宾"""
names = ['Einstein','Plonk','Huangdi']
for item in names:
print("Hello, " + item + ", I would like to invite you to have a dinner with me.")
print("I have invite " + str(len(names)) + " people to have a dinner together")

你可能感兴趣的:(第三章作业)