谪仙阁-记录美好瞬间

Python作业

作者头像
谪仙 本文作者

2026-3-24 阅读 105 约 2分钟读完

评论0

weather = 'sunny,windy,sunny,rainy,rainy,windy,sunny,windy,sunny,rainy'
wlist = weather.split(',')
result = {w:wlist.count(w) for w in set(wlist)}

print('天气:次数')
for k,v in result.items():
    print(k,v,sep=':')
stu = {"zxc": 58, "asd": 70, "qwe": 89}
s = stu.copy()

s.update({'ghj': '缺考'})
print(s)

s.update({'fgh': 60})
print(s)

# 安全移除 'xxw',如果不存在则给出提示
if 'xxw' in s:
    result = s.pop('xxw')
    print("移除的 xxw 的值:", result)
else:
    print("xxw 不在字典中,无法移除")
print(s)

print("字典长度:", len(s))

x = input("请输入名字:")
# 安全访问,避免 KeyError
if x in s:
    print("成绩:", s[x])
else:
    print(f"未找到 {x} 的成绩")


手机扫码阅读
上一篇 多媒体 下一篇 重返 2016:Minecraft 0.14.3 “基岩服”
评论