Python编程:从入门到实践 动手试一试 3.1-3.10

#3.1 names

names = ['Ricky', 'Leo', 'Jerry', 'Pegasus']
print(names[0])
print(names[1])
print(names[2])
print(names[3])

#3.2 greeting

print("Hello, " + names[0] + "! I'm happy to see you back!")
print("Hello, " + names[1] + "! I'm happy to see you back!")
print("Hello, " + names[2] + "! I'm happy to see you back!")
print("Hello, " + names[3] + "! I'm happy to see you back!")

list_of_transformation = ['motorcycle', 'car', 'bus', 'subway']
print("I would like to take " + list_of_transformation[3] + " to work on the week days)

#3.4 guests list

guests = ['pan xiangdi', 'he bosheng', 'jiang nan',]

print("Dear, " + guests[0].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[1].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[2].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")

#3.5 modifying the guests list

print("\nThe " + guests[0] + " isn't available for the dinner party!\n")
del guests[0]
guests.insert(0, 'wang shaoqin')

print("Dear, " + guests[0].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[1].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[2].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")

#3.6 adding more guests!

print("\nI need a bigger dinning table for the party!\n")
guests.insert(0, 'zeng sufang')
guests.insert(0, 'huang ziqin')
guests.append('leo han')

print("Dear, " + guests[0].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[1].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[2].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[3].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[4].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")
print("Dear, " + guests[5].title() + "!, I'm delightful to invite you to participate the dinner party at 5th of Nov.")

#3.7 subtract guests list!

print('\nDue to the delayed delivery of dinning table, I can only invite two guests to the dinner party.\n')
out_guest_1 = guests.pop(0)
print("Dear, "+ out_guest_1 + ", I'm so sorry that due to some reasons, the dinner party is going to be re-arrange.")
out_guest_2 = guests.pop(0)
print("Dear, "+ out_guest_2 + ", I'm so sorry that due to some reasons, the dinner party is going to be re-arrange.")
out_guest_3 = guests.pop(1)
print("Dear, "+ out_guest_1 + ", I'm so sorry that due to some reasons, the dinner party is going to be re-arrange.")
out_guest_4 = guests.pop(2)
print("Dear, "+ out_guest_1 + ", I'm so sorry that due to some reasons, the dinner party is going to be re-arrange.")

print("\nDear, " + guests[0] + " please come to the dinner party!")
print("Dear, " + guests[1] + " please come to the dinner party!")

del guests[0]
del guests[0]

print(guests)

#3.8 see the world!

places_I_would_like_to_go = ['Beijin', 'Shanghai', 'London', 'New York', 'Dubai']
print(places_I_would_like_to_go)
print(sorted(places_I_would_like_to_go))
print(places_I_would_like_to_go)
print(sorted(places_I_would_like_to_go, reverse=True))
print(places_I_would_like_to_go)
places_I_would_like_to_go.reverse()
print(places_I_would_like_to_go)
places_I_would_like_to_go.reverse()
print(places_I_would_like_to_go)
places_I_would_like_to_go.sort()
print(places_I_would_like_to_go)
places_I_would_like_to_go.sort(reverse=True)
print(places_I_would_like_to_go)

#3.9 dinner guests

guests = ['Jiang Nan', 'Wang Shaoqin']
print('There are ' + str(len(guests)) + ' guests I invited to the dinner party')

#3.10 attempting to use different functions

#unnecessarily to do as it's repeatitive, so just drop it.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值