#3-1
names = ['pp', 'ydm', 'wzy', 'cx']
for name in names:
print(name)
#3-2for name in names:
print(name, 'f**k you')
#3-3
transportation = ['automobile', 'subway', 'bicycle', 'foot']
print('I own one', transportation[0])
print('I prefer taking', transportation[1], 'to travel around the cith')
print('I am able to ride a', transportation[2], 'to my classroom')
print('I usually go to school on', transportation[3])
#3-4fornamein names:
print('come here and eat a big meal together,', name)
#3-5
print(names[0], 'is busy with study and can not come tothe dinner')
del names[0]
fornamein names:
print('come here and eat a big meal together,', name)
#3-6
print('I am really rich and have got a big table for you guys')
names.insert(0, 'pp')
names.insert(2, 'zyc')
names.append('zxy')
for name innames:
print('come here and eat a big meal together,', name)
#3-7print('Bazinga! Only two guys will be invited')
while len(names) > 2:
print(names.pop(), 'out!')
for name in names:
print(name + ', you got it!')
while names:
names.pop()
print(names)
#3-9
print('thenumberof total invited members:',len(names))
#3-11print('length of names:', len(names))
#for i in range(1, 10): 越界
#print(names[i])
for i in range(0, 10):
names.append(i)
for i in range(1, 10):
print(names[i])
第四章作业
#4-1
pizzas = ['cheese', 'sausage', 'chicken']
for pizza in pizzas:
print('I like', pizza, 'pizza')
print('''I really don't like pizza''')
#4-2
animals = ['puppy', 'kitty', 'eagle', 'pig']
for animal in animals:
print(animal, 'can be a great and lovely pet')
print('All of these animals can be a pet for us')
#4-3fornumin range(1, 21):
print(num)
#4-4
million = list(range(1, 1000001))
#for m in million:# print(m)
#4-5#print(sum(million))
#4-6
odds = list(range(1, 20, 2))
for odd in odds:
print(odd)
#4-7three = [i for i in range(3, 31) if i % 3 == 0]
for t inthree:
print(t)
#4-8
cube = [i ** 3for i in range(1, 11)]
for c in cube:
print(c)
#4-9
cube = [i ** 3for i in range(1, 11)]
#4-10
print('The first three items inthelist are:')
for i in cube[:3]:
print(i)
print('Three items fromthemiddleofthelist are:')
for i in cube[2:5]:
print(i)
print('The last three items inthelist are:')
for i in cube[-3:]:
print(i)
#4-13
foods = ('pork', 'beef', 'chicken', 'bread', 'shit')
for food in foods:
print(food)
#foods[0] = 'milk'
foods = ('milk', 'vegetable', 'chicken', 'bread', 'shit')
for food in foods:
print(food)