这道题该如何处理invalid literal for int() 这个报错?
求解该怎么改? 发文本形式的代码 fo = open("PY202.txt","w")data = input("请输入课程名及对应的成绩:")
a={}
while data:
xueke,chengji=data.split(' ')
a=int(chengji)
data = input("请输入课程名及对应的成绩:")
c=list(a)
c.sort(key=lambda x:x,reverse=True)
zuigaoxk=c
zuigaofen=c
zuidixk=c[-1]
zuidifen=c[-1]
zongfen=0
for i in range(len(c)):
zongfen+=int(c)
pingfen=zongfen/len(c)
fo.write("最高分课程是{} {}, 最低分课程是{} {}, 平均分是{:.2f}".format(zuigaoxk,zuigaofen,zuidixk,zuidifen,pingfen))
fo.close()
qiuyouzhi 发表于 2021-2-26 16:43
发文本形式的代码
ok
shaojianjian 发表于 2021-2-26 16:46
ok
改成这样:
fo = open("PY202.txt","w")
data = input("请输入课程名及对应的成绩:")
a={}
while data:
xueke,chengji=data.split(' ')
a=int(chengji)
data = input("请输入课程名及对应的成绩:")
c=list(a.items())
c.sort(key = lambda x : x, reverse=True)
zuigaoxk=c
zuigaofen=c
zuidixk=c[-1]
zuidifen=c[-1]
zongfen=0
for i in range(len(c)):
zongfen += int(c)
pingfen=zongfen/len(c)
fo.write("最高分课程是{} {}, 最低分课程是{} {}, 平均分是{:.2f}".format(zuigaoxk,zuigaofen,zuidixk,zuidifen,pingfen))
fo.close() fo = open("PY202.txt","w")
data = input("请输入课程名及对应的成绩:")
a={}
while data:
xueke,chengji=data.split(' ')
a=int(chengji)
data = input("请输入课程名及对应的成绩:")
#c=list(a)
c=sorted(a.items(),key=lambda x:x,reverse=True)
zuigaoxk=c
zuigaofen=c
zuidixk=c[-1]
zuidifen=c[-1]
zongfen=0
for i in range(len(c)):
zongfen+=int(c)
pingfen=zongfen/len(c)
fo.write("最高分课程是{} {}, 最低分课程是{} {}, 平均分是{:.2f}".format(zuigaoxk,zuigaofen,zuidixk,zuidifen,pingfen))
fo.close()
print("最高分课程是{} {}, 最低分课程是{} {}, 平均分是{:.2f}".format(zuigaoxk,zuigaofen,zuidixk,zuidifen,pingfen))
data = input("请输入课程名及对应的成绩:")
a={}
while data:
xueke,chengji=data.split(' ')
a=int(chengji)
data = input("请输入课程名及对应的成绩:")
zuigaoxk=list(i for i in a if a == max(a.values()))
zuigaofen=max(a.values())
zuidixk=list(i for i in a if a == min(a.values()))
zuidifen=min(a.values())
zongfen = sum(a.values())
pingfen=zongfen/len(a)
with open('PY202.txt','w') as fo:
fo.write("最高分课程是{} {}, 最低分课程是{} {}, 平均分是{:.2f}".format(zuigaoxk,zuigaofen,zuidixk,zuidifen,pingfen))
逃兵 发表于 2021-2-26 17:17
谢谢 qq1151985918 发表于 2021-2-26 17:15
谢谢
页:
[1]