homework_week2

##Q 3-1~3-3

1
2
3
4
5
6
7
8
9
names=["YeGuangzhi","Yinjiyi","Yangchenze"]
print(names[0])
print(names[1])
print(names[2])
for friend in names:
print("Hello,", friend)
Transpot=["biycle","car","plane"]
for T in Transpot:
print("I want to go home by ",T)

##Q 3-4~3-7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
guest=["Mike","Stack","Ezio","Masiluo"]
for g in guest:
print("I would like to invite you to attend my party," , g)
print(guest[0],"can't come")
guest[0]="White_Wolf"
for g in guest:
print("I would like to invite you to attend my party," , g)
print("I find a better table")
guest.insert(0,"Bayoneta")
guest.insert(2,"Steve")
guest.append("Taloyer")
for g in guest:
print("I would like to invite you to attend my party," , g)
print(len(guest))
print("For some unknown reason,I can only invite two people")
for g in guest[2:]:
print("I am sorry about that",g)
guest.pop()
print(guest[0],"is in the list ")
print(guest[1],"is in the list")
del guest[1]
del guest[0]
if not guest:
print("The list is empty")

##Q 3-8、4-10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
place=["Haerbin","Tibet","Changsha","Janpan","Europe"]
print(place)
print(sorted(place))
print(place)
print(sorted(place,reverse=True))
print(place)
place.reverse()
print(place)
place.reverse()
print(place)
print(place)
place=sorted(place)
print(place)
place=sorted(place,reverse=True)
print(place)
M1="The first three items in the list are"
M2="Three items from the middle of the list are:"
M3="The last three items in the list are"
print(M1,place[:3])
print(M2,place[1:-1])
print(M3,place[-3:])

##Q 4-3~4-9

1
2
3
4
5
6
7
8
9
10
11
12
for i in range(1,20):
print(i)
l=range(1,1000000)
print(min(l))
print(max(l))
print(sum(l))
l=range(1,20,2)
for num in l:
print(num)
k=[i**3for i in range(1,10)]
for num in k:
print(num)