第三、四章编程练习
3-1
name = ['William','Jack','Sherry','Ivy']
print(name)
3-2
name = ['William','Jack','Sherry','Ivy']
print(name[0] + 'How are you?')
print(name[1] + 'How are you?')
print(name[2] + 'How are you?')
print(name[3] + 'How are you?')
3-4
guest = ['William','Jack','Sherry','Ivy']
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')
3-6
guest = ['William','Jack','Sherry','Ivy']
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')
print("I have a bigger table!")
guest.insert("Washington",0)
guest.insert("Amy",1)
guest.append("Jimmy")
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')
print(guest[4] + ' Welcome to the party!')
print(guest[5] + ' Welcome to the party!')
print(guest[6] + ' Welcome to the party!')
3-9
guest = ['William','Jack','Sherry','Ivy']
print(guest[0] + ' Welcome to the party!')
print(guest[1] + ' Welcome to the party!')
print(guest[2] + ' Welcome to the party!')
print(guest[3] + ' Welcome to the party!')
print('I have ' + len(guest) + ' guests.')
4-1
pizzas = ["Italy","Sausage","Beef"]
for pizza in pizzas
print("I like " + pizza + " pizza.")
print("I love pizzas.")
4-3
for i in range(1,21)
print(i)
4-6
num = list(range(1,20,2))
for i in num
print(i)
4-7
num = list(range(3,31,3))
for i in num
print(i)
4-9
a = list(range(1,11))
b = []
for i in a
b.append(i**3)
for k in b
print(k)