4-1比萨
pizza=['a','b','c']
for i in pizza:
print(i)
for i in pizza:
print('I really love '+i+'!')
4-2动物
anmimals=['dog','cat','pig']
for i in anmimals:
print(i)
for i in anmimals:
print('A '+i+' would make a great pet')
print('Any of these animals would make a great pet')
animals = ['dog','cat','mouse']
for i in animals:
print("A %s would make a great pet"%i)
print("They all have four legs.")
4-3数到20
for i in range(1,21):
print(i)
4-4一百万
numbers=list(range(1,1000001))
print(numbers)
4-5计算1-一百万的总和
numbers = list(range(1,1000001))
print(min(numbers))##求最小
print(max(numbers))#最大
print(sum(numbers))#总和
4-6奇数
bon=list(range(1, 21, 2))
print(bon)
for i in bon:
print(i)
4-7 3的倍数
numbers = list(range(3,31,3))
for i in numbers:
print(i)
4-8立方
a = list(range(1, 11))
for i in [i ** 3 for i in a]:
print(i)
4-9立方解析
list = [a**3 for a in range(1,11)]
print(list)
4-10 切片
a = list(range(1, 6))
print("The first three items in the list are:")
print(a[0:3])
print("The items from the middle of the list are:")
print(a[1:4])
print("The last three items in the list are:")
print(a[-3:])
4-11你的比萨和我的比萨
mypizza = ['banana','milk','apple']
friend_pizzas = mypizza[:]
friend_pizzas.append("org")
print("my favorite pizzas are:")
for i in mypizza:
print(i)
print("My friends favorite foods are:")
for i in friend_pizzas:
print(i)
4-12使用多个循环
mypizza = ['banana','milk','apple']
for i in mypizza:
print(i)
4-13自助餐
#第一个元组
yuanzu=(1,2,3,4,5)
for i in yuanzu:
print(i)
#此处发现修改元组不大行啊
#改变元组
yuanzu=(2,3,4,5,6)
for i in yuanzu:
print("\t",i)#为了和上面输出分开,好展示结果
4-14 PEP 8
略
4-15 代码审核
略