#3.1
names = ["John","Joe","Janes"]
for name in names:
print(name)
#3.2
names = ["John","Joe","Janes"]
for name in names:
print(name + ", Hello!")
#3.3
tools = ["bike","car","bus"]
for t in tools:
print("I would like to own a " + t)
#3.4
names = ["John","Joe","Janes"]
for name in names:
print(name + ", come and take part in the dinner")
#3.5.1
names = ["John","Joe","Janes"]
for name in names:
print(name + ", come and take part in the dinner")
print("It's so sorry that "+names[0] +" can't come")
#3.5.2
names[0] = "Pig"
#3.5.3
for name in names:
print(name + ", come and take part in the dinner")
#3.6
print("I find a big desk")
names.insert(0, "Kitter")
names.insert(int(len(names)/2), "Cat")
names.append("FISH")
for name in names:
print(name + ", come and take part in the dinner")
#3.7
print("I invite " + names[0] +" and " + names[1])
while len(names) != 2:
n = names.pop()
print(n + ", I am very sorry!")
for n in names:
print("I invite you, " + n)
del names[0]
del names[0]
print(names)
#3.8
places = ["Beijing" , "Hong Kong" , "Changsha","Wuhan","Foshan"]
for p in places:
print(p)
for p in sorted(places):
print(p)
for p in places:
print(p)
temp = sorted(places)
temp.reverse()
for p in temp:
print(p)
for p in places:
print(p)
places.reverse()
for p in places:
print(p)
places.reverse()
for p in places:
print(p)
places.sort()
for p in places:
print(p)
places.sort(reverse = True )
for p in places:
print(p)
#3.9
print("I have invited " + str(len(names)) + " person")
#3.10
p = ["Changjiang","Huanghe","Taishan","Huangshan"]
p.sort()
for i in p:
print(i)
p.reverse()
for i in p:
print(i)
for i in sorted(p):
print(i)
print(len(p))
#3.11
l = [1,2]
print(l[2])
结果:
==================== RESTART: C:/Users/Jing/Desktop/a.py ====================
John
Joe
Janes
John, Hello!
Joe, Hello!
Janes, Hello!
I would like to own a bike
I would like to own a car
I would like to own a bus
John, come and take part in the dinner
Joe, come and take part in the dinner
Janes, come and take part in the dinner
John, come and take part in the dinner
Joe, come and take part in the dinner
Janes, come and take part in the dinner
It's so sorry that John can't come
Pig, come and take part in the dinner
Joe, come and take part in the dinner
Janes, come and take part in the dinner
I find a big desk
Kitter, come and take part in the dinner
Pig, come and take part in the dinner
Cat, come and take part in the dinner
Joe, come and take part in the dinner
Janes, come and take part in the dinner
FISH, come and take part in the dinner
I invite Kitter and Pig
FISH, I am very sorry!
Janes, I am very sorry!
Joe, I am very sorry!
Cat, I am very sorry!
I invite you, Kitter
I invite you, Pig
[]
Beijing
Hong Kong
Changsha
Wuhan
Foshan
Beijing
Changsha
Foshan
Hong Kong
Wuhan
Beijing
Hong Kong
Changsha
Wuhan
Foshan
Wuhan
Hong Kong
Foshan
Changsha
Beijing
Beijing
Hong Kong
Changsha
Wuhan
Foshan
Foshan
Wuhan
Changsha
Hong Kong
Beijing
Beijing
Hong Kong
Changsha
Wuhan
Foshan
Beijing
Changsha
Foshan
Hong Kong
Wuhan
Wuhan
Hong Kong
Foshan
Changsha
Beijing
I have invited 0 person
Changjiang
Huanghe
Huangshan
Taishan
Taishan
Huangshan
Huanghe
Changjiang
Changjiang
Huanghe
Huangshan
Taishan
4
Traceback (most recent call last):
File "C:/Users/Jing/Desktop/a.py", line 97, in <module>
print(l[2])
IndexError: list index out of range