Python编程:从入门到实践的动手试一试答案(第四章)

学习中,用于记录学习。不喜勿喷,谢谢 

#4-2
pizzas = ["pizza_hut","papa John's","apple_pizza"]
for pizza in pizzas:
    print('I like pepperoni pizza:'+ pizza.title())
print('\nI really love pizza!')

#4-3 数到 20
for i in range(1,21):
    print(i)

#4-4 一百万
numbers = list(range(1,1000001))
for number in numbers:
   print(number)

#4-5 计算 1-10000
number = list(range(1,1000001))
print(min(number))

print(max(number))

#4-6 奇数
num = list(range(1,21,2))
for ji in num:
    print(ji)

#4-7 3的倍数
num_3 = []
for value in range(3,31,3):
    num_3.append(value)
for num in num_3:
    print(num)

#4-8 立方
squares = []
nums_3 = list(range(1,11)) # for value in range(1,11):这样写更好
for value in nums_3:
    square = value**3
    squares.append(square)
for squaress in squares:
    print(squaress)
#4-9
squares = [value**3 for value in range(1,11)]
print(squares)

#4-10
squares = [value**3 for value in range(1,11)]
print(squares)
print("The first three items in the list are:")
print(squares[0:3])
print("Three irems from the middle of the list are:" )
print(squares[5:8])
print("The last three items in the list are:" )
print(squares[-3:])

#4-11
pizzas = ["pizza_hut","papa John's","apple_pizza"]
for pizza in pizzas:
    print('I like pepperoni pizza:'+ pizza.title())
print('\nI really love pizza!')

friend_pizzas = pizzas[:]

pizzas.append('pizza')

friend_pizzas.append('banana_pizza')

print('My favorite pizzas are:')
for pizza_1 in pizzas:
    print(pizza_1)

print('My friends favorite pizzas are:')
for friend_pizza in friend_pizzas:
    print(friend_pizza)
#

 

你可能感兴趣的:(Python编程:从入门到实践)