【HW】第三章作业 2018.3.12

Python代码:

#Chapter 3 homework   by szh 2018.3.12
print("3.1")
names = ['Alice', 'Bob', 'jack', 'lucy']
for name in names:
	print(name)

print("\n3.2")
greet_word = ", I'm happy to meet you."
for name in names:
	print(name + greet_word) 	

print("\n3.3")
commutes = ['Tropix bicycle', 'Honda motorcycle', 'BWM car']
for commute in commutes:
	print(" “I would like to own a " + commute + ".")

print("\n3.4")
names = ['Alice', 'Bob', 'jack', 'lucy']
for name in names:
	print("Dear " + name + ", I'm invite you to dinner sincerely.")

print("\n3.5")
print("Oh, it's a pity that" + names[-1] + " is to busy so that couldn't coming.")
names[-1] = 'Mack'
for name in names:
	print("Dear " + name + ", I'm invite you to dinner sincerely.")

print("\n3.6")
print("I had find a bigger table, so I want to invite more people.")
names.insert(0, 'Turing')
names.insert(2, 'Einstein')
names.append('Dash')
for name in names:
	print("Dear " + name + ", I'm invite you to dinner sincerely.")

print("\n3.7")
print("I'm so sorry that because the table's problem, I can only invite two people.")
while len(names) > 2:
	name = names.pop()
	print("Dear " + name + ", I'm so sorry to tell you that I couldn't invite you to the dinner.")
for name in names:
	print("Dear " + name + ", you are still in my list.")
del names[1]
del names[0]
print(names)

print("\n3.8")
places = ['Maldives', 'Paris', 'Moscow', 'Washington', 'Hawaii']
print(places)
print(sorted(places))
print(places)
print(sorted(places, reverse = True))
places.reverse()
print(places)
places.reverse()
print(places)
places.sort()
print(places)
places.sort(reverse = True)
print(places)

输出结果

3.1
Alice
Bob
jack
lucy

3.2
Alice, I'm happy to meet you.
Bob, I'm happy to meet you.
jack, I'm happy to meet you.
lucy, I'm happy to meet you.

3.3
 “I would like to own a Tropix bicycle.
 “I would like to own a Honda motorcycle.
 “I would like to own a BWM car.

3.4
Dear Alice, I'm invite you to dinner sincerely.
Dear Bob, I'm invite you to dinner sincerely.
Dear jack, I'm invite you to dinner sincerely.
Dear lucy, I'm invite you to dinner sincerely.

3.5
Oh, it's a pity thatlucy is to busy so that couldn't coming.
Dear Alice, I'm invite you to dinner sincerely.
Dear Bob, I'm invite you to dinner sincerely.
Dear jack, I'm invite you to dinner sincerely.
Dear Mack, I'm invite you to dinner sincerely.

3.6
I had find a bigger table, so I want to invite more people.
Dear Turing, I'm invite you to dinner sincerely.
Dear Alice, I'm invite you to dinner sincerely.
Dear Einstein, I'm invite you to dinner sincerely.
Dear Bob, I'm invite you to dinner sincerely.
Dear jack, I'm invite you to dinner sincerely.
Dear Mack, I'm invite you to dinner sincerely.
Dear Dash, I'm invite you to dinner sincerely.

3.7
I'm so sorry that because the table's problem, I can only invite two people.
Dear Dash, I'm so sorry to tell you that I couldn't invite you to the dinner.
Dear Mack, I'm so sorry to tell you that I couldn't invite you to the dinner.
Dear jack, I'm so sorry to tell you that I couldn't invite you to the dinner.
Dear Bob, I'm so sorry to tell you that I couldn't invite you to the dinner.
Dear Einstein, I'm so sorry to tell you that I couldn't invite you to the dinner.
Dear Turing, you are still in my list.
Dear Alice, you are still in my list.
[]

3.8
['Maldives', 'Paris', 'Moscow', 'Washington', 'Hawaii']
['Hawaii', 'Maldives', 'Moscow', 'Paris', 'Washington']
['Maldives', 'Paris', 'Moscow', 'Washington', 'Hawaii']
['Washington', 'Paris', 'Moscow', 'Maldives', 'Hawaii']
['Hawaii', 'Washington', 'Moscow', 'Paris', 'Maldives']
['Maldives', 'Paris', 'Moscow', 'Washington', 'Hawaii']
['Hawaii', 'Maldives', 'Moscow', 'Paris', 'Washington']
['Washington', 'Paris', 'Moscow', 'Maldives', 'Hawaii']

猜你喜欢

转载自blog.csdn.net/empire_03/article/details/79529184