python 入门到实践第四章课后练习

  """这是第四章的练习题"""

"""4-1"""
pizzas = ["red","big","blnk"]#定义一个列表
mes = "I like pepperoni pizza"#定义一个消息字符串
for pizza in pizzas:#for循环取列表中的值
print(pizza + " , " + mes + ".\n")
print("I really love pizza!")
"""4-2"""
animals = ["dog","cat","pig"]
for animal in animals:
print("a" + " "+ animal + " would make a great pet")
print("Any of these animals would make a preat pet")
"""4-3"""
num = range(1,21)
for i in num:
print(i)
"""4-4,4-5"""
numa = list(range(1,1000001))#定义一个列表,从1到1000001
for i in numa:
print(i)
print(min(numa))#求列表中最小值
print(max(numa))#求列表中最大值
print(sum(numa))#求列表和
"""4-6"""
numb = list(range(1,21,2))#定义一个列表,从1到21中其中步长为2的数字(奇数)
for i in numb:
print(i)
"""4-7"""
numc = []#定义一个空的列表
temp = range(1,11)
for i in temp:
numc.append(i**3)#用append方法把值写入numc的列表中
for x in numc:#循环取值
print(x)
"""4-9"""
numd=[numd**3 for numd in range(1,11)]#使用列表解析生产一个列表
print(numd)
上一篇:四则运算 计应191(西)张壮飞


下一篇:大数减法(A - B Problem Plus)问题