python作业ch3和ch4

3-1

names = [ 'John', 'Amy', 'Green', 'Jackson']
for name in names:
print(name)

3-2

names = [ 'John', 'Amy', 'Green', 'Jackson']
for name in names:
print(name + ', how are you recently?')

3-4

names = [ 'John', 'Amy', 'Green']
print(names[ 0] + ', ' + names[ 1] + ' and ' + names[ 2] +
", may I have the pleasure of inviting you to dinner?")

3-5

names = [ 'John', 'Amy', 'Green']
print(names[ 0] + ', ' + names[ 1] + ' and ' + names[ 2] +
", may I have the pleasure of inviting you to dinner?")

print( "John can not keep the appointment!")

names[ 0] = 'Terry'
print(names[ 0] + ', ' + names[ 1] + ' and ' + names[ 2] +
", may I have the pleasure of inviting you to dinner?")

3-6

names.insert( 0, 'Jackson')
names.insert( 3, 'Tom')
names.append( 'Klay')
for name in names:
print(name + ', ', end = "")
print( "may I have the pleasure of inviting you to dinner?")

3-7

print( "I can only invite two friends!")
while len(names) > 2:
name = names.pop()
print(name + ', I am very sorry that I can not invite you to dinner!')
for name in names:
print(name + ", may I have the pleasure of inviting you to dinner?")

while len(names) != 0:
del names[ 0]
print(names)


3-8

points = [ 'San Francisco', 'Seattle', 'Mexico City', 'Toronto', 'Beijing']
print(points)
print( sorted(points))
print(points)
print( sorted(points, reverse = True))
print(points)
points.reverse()
print(points)
points.reverse()
print(points)
points.sort()
print(points)
points.sort( reverse = True)
print(points)

4-1

pizzas = [ 'Beef', 'pepperoni', 'Corn', 'Mushroom', 'Salmon']
for pizza in pizzas:
print( 'I like ' + pizza + ' pizza!')
print( 'I really like pizza!')


4-3

for i in range( 1, 20):
print(i)


4-4

numbers = list( range( 1, 1000001))
for number in numbers:
print(number)


4-5

numbers = list( range( 1, 1000001))
print( max(numbers))
print( min(numbers))
print( sum(numbers))


4-9

squares = [value ** 2 for value in range( 1, 11)]
print(squares)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值