[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
1、 打分实现
#-*- codeing =utf-8 -*- #@Author:致远 #@File:test.py #@Software:PyCharm scores =
[] #定义列表存储分数 #n = int(input("评委人数:")) for i in range(10): score =
float(input(f"请输入第{i+1}名评委的打分:"))#输入分数 while score < 0 or score > 100: score =
float(input("打分错误,请重新打分:")) scores.append(score)#将打分存入列表中 max_score =
max(scores)#取最大值 min_score = min(scores)#取最小值 print(f"去掉一个最低分: {min_score}")
scores.remove(min_score)#去最小值 print(f"去掉一个最高分: {max_score}")
scores.remove(max_score)#去最大值 print("该歌手的得分为: %.2f" % (sum(scores) /
len(scores)))#总分
* 定义一个空列表接收评委的打分 :scores = []
* 在for循环中接收打分,并对分数进行判断:scores.append(score)#使用append函数将打分存入列表中
* 判断高低分,然后使用remove函数去掉高低分
2、猜拳实现:
import random player =int(input('玩家出拳:0-石头,1-剪刀,2-布:')) computer =
random.randint(0,2) //随机生成0~2的整数 print('电脑出拳:%d' % computer) if (
(player==0)and(computer==1) or (player==1)and(computer==2) or
(player==2)and(computer==0) ): print('玩家获胜:') elif player == computer:
print('平局')
3、1-100偶数累加实现:
法一:
i = 1 sum = 0 while i <= 100: if i%2==0: #判断是否为偶数 sum = sum + i i += 1
print(sum)
法二:
i = 0 # 初值为0 sum = 0 while i <= 100: if i%2==0: sum = sum + i i += 2 #增量每次加2
print(sum)
4、退出循环:break(终止整个循环)、continue(跳过循环,执行下一条)
continue:
i = 1 while i <= 5: if i == 4: print('跳过该次') i+=1 #不加此语句,会进入死循环 continue
print(i) i+=1
break:
#break i = 1 while i <= 5: if i == 4: print('退出循环') break print(i) i+=1
5、嵌套循环:
j=0 while j<5: i = 0 while i<3: print('我错了') i+=1 print('写作业')
print('惩罚结束***************************') j+=1
i变量控制每天做某事做多少次,j变量相当于控制这件事做多少天