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} 的成绩") 文章作者:zhexian
文章标题:Python作业
文章链接:https://zhexiange.com/39.html
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明来自zhexian !
文章标题:Python作业
文章链接:https://zhexiange.com/39.html
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明来自zhexian !
手机扫码阅读

