python编程从基础到实践第四章

课堂学习及课后练习

students = ['贾克斯','科加斯','拉克丝','金克斯','吉格斯']
#unexpected indent,不必要的缩进
	#print(students)
for student in students:
	print(student) #expected an indented block:期望一个缩进的块
maginc = ['alice','jiakesi','kejiasi','jinkesi','jigesi']
for people in maginc:
	print(f"The\t{people}\tis\ta\tgreat\tteacher")
	print(f"It\twai\ta great patty, if you think so? {people.title()}")
	print(f"It\twai\ta great patty, if you think so? {people.title()}\n")#这里换行的意思是把循环一遍后空一行再循环
print("it was a great show!")
animals = ['dog','cat','duck','pig']
for animal in animals:
	print(f"l love {animal}")
	print("it is our friends!")
print("they are delicious!")
for value in range(1,5):
	print(value)#差1行为,在倒数第二个数时结束运行
number = list(range(1,6))#list是把数字转为列表
print(number)
twice = list(range(2,11,2))#从2到11,依次加2,直到数字达到或超过11
print(twice)
squares = []
for value in range(1,11):
	squares.append(value ** 2)
print(squares)
print(min(squares))
print(max(squares))
print(sum(squares))
squares = [value**2 for value in range(1,12)]
print(squares)
#max_number = list(range(1,1000_000))
#for value in max_number:
#	print(value)
#print(min(max_number))
#print(sum(max_number))
three_times = [value for value in range(1,21,2)]
print(three_times)
three_times = [value for value in range(3,33,3)]
print(three_times)
li_fang = [value**3 for value in range(1,11)]
print(li_fang)
players = ['aaa','bbb','ccc','ddd','eee']
print(players[0:3])#切片,选择列表里面的数据
print("the best friend is:")
for player in players[:3]:
	print(player.title())
copy_players = players[:]
print(copy_players)
print(f"The first three items in the list are:{players[:3]}")
print(f"The items from the middle of the list are:{players[2:4]}")
print(f"the last three items are:{players[-3:]}")
fruit_pizza = ['apple','orange','pear','banana','shit']
friend_pizza = fruit_pizza[:]
fruit_pizza.append('jiaozi')
friend_pizza.append('goushi')
print(fruit_pizza)
print(friend_pizza)
print("my friend like eat:")
for pizza in friend_pizza:
	print(pizza)
print("I do not like :")
for pizza in fruit_pizza:
	print(pizza)
sum_monkey = ('xingzhe','wukong','fo','monkeyking')
print(sum_monkey[3])
for id_monkey in sum_monkey:
	print(id_monkey)
sum_monkey = (0)
print(sum_monkey)
important_food = ('H','He','Li','Pi','Pe')
for food in important_food:
	print(food)
important_food = ('H','He','Fe','Li','Ca')
for food in important_food:
	print(food)




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值