python學習第2周(1)

#python課後作業
#3-1,2
names = ["Wuzy", "Xul", "Xusw"]
for name in names:
print(name + ", How are you.")

#3-3
vehicles = ["car", "bike", "motorbike"]
for vehicle in vehicles:
print("I would like to own a " + vehicle)

#3-4,5,6,7
guests = ["Ben", "Kite", "Lihua"]
for guest in guests:
print("Dear " + guest + ", I would like to invite you for dinner!")

print(guests[0] + ": No thanks")
guests[0] = "Lili"
for guest in guests:
print("Dear " + guest + ", I would like to invite you for dinner!")

print("I find a bigger dinner-table")
guests.insert(0, "Jack")
guests.insert(2, "James")
guests.append("Kobe")
for guest in guests:
print("Dear " + guest + ", I would like to invite you for dinner!")


print("I am sorry that I will invite just two guests.")
for i in range(0,4):
print("I am sorry that I can invite you for dinner, " + guests.pop())
for guest in guests:
print("Dear " + guest + ", I would like to invite you for dinner!")
del guests[0]
del guests[0]
print(guests)


#3-8,9
citys = ["Beijing", "Hangzhou", "Guangzhou", "Chengdu", "Shanghai"]
print(citys)
print(sorted(citys))
print(citys)
print(sorted(citys,reverse = True))
print(citys)
citys.reverse()
print(citys)
citys.reverse()
print(citys)
citys.sort()
print(citys)
citys.sort(reverse = True)
print(citys)
print("There are " + str(len(citys)) + " citys.")
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章