#题目1
tech_list=["Python","Java","Go"]
first_tech=tech_list[0]
tech_list.append("JavaScript")
tech_list[1]="Ruby"
tech_list.remove("Go")
current_length=len(tech_list)
print(f"第一个技术是:{first_tech}\n当前列表长度:{current_length}\n最终列表内容:{tech_list}")
#题目2
sum=0
for i in range(1,101):
sum+=i
print(f"累加和是:{sum}")
#题目3
temperature = 38
if temperature > 35:
print("红色预警:高温天气!")
elif temperature >=28 :
print("黄色预警:天气炎热")
elif temperature >= 20:
print("绿色提示:适宜温度")
else:
print("蓝色预警:注意保暖")
#题目4
scores=[85,92,78,65,95,88]
excellent_count=0
total_score=0
for score in scores:
total_score+=score
if score>=90:
excellent_count+=1
average_score=total_score/len(scores)
print(f"优秀分数个数:{excellent_count}\n分数总和:{total_score}\n平均分数:{average_score:.3f}")
小结:
1.列表函数len、append、remove
2.范围循环range左闭右开
3.if语句的elseif在Python里是elif
4.保留x小数位写法 .xf

被折叠的 条评论
为什么被折叠?



