问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容


读取每行用.split()以空格分割,并用float()转为数值计算即可
你题目的解答代码如下:
with open(r'suanshi.txt', 'r', encoding='utf-8') as rf,open(r'jieguo.txt', 'w', encoding='utf-8') as wf:
for d in rf.readlines():
li = d.strip().split()
a = float(li[0])
b = float(li[1])
print(f"{a:.1f}+{b:.1f}={a+b:.1f}")
wf.write(f"{a:.1f}+{b:.1f}={a+b:.1f}\n")


第二个
s = input()
dic1 = {}
dic2 = {}
for v in s:
if v.islower():
dic1[v] = dic1.get(v,0)+1
if v.isupper():
dic2[v] = dic2.get(v,0)+1
li1 = sorted(dic1.items(),key=lambda x: x[0])
li2 = sorted(dic2.items(),key=lambda x: x[0])
for c,v in li1:
print(f'{c} {v}')
for c,v in li2:
print(f'{c} {v}')
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!