Python day3

@浙大疏锦行

#题目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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值