|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
list1=[1,2,3,4]
list2=[98,67,89,80]
list3=[100,90,83,62]
list4=[90,98,100,82]
num=eval(input("请输入您的学号:"))
while num == (list1[0]):
print("该学生成绩为语文",list2[0],",数学",list3[0],",英语",list4[0],",总分",sum(list2[0]+list3[0]+list4[0]))
break
while num == (list1[1]):
print("该学生成绩为语文",list2[1],",数学",list3[1],",英语",list4[1],",总分",sum(list2[1]+list3[1]+list4[1]))
break
while num == (list1[2]):
print("该学生成绩为语文",list2[2],",数学",list3[2],",英语",list4[2],",总分",sum(list2[2]+list3[2]+list4[2]))
break
while num == (list1[3]):
print("该学生成绩为语文",list2[3],",数学",list3[3],",英语",list4[3],",总分",sum(list2[3]+list3[3]+list4[3]))
break
else:
print()
哪里出现了问题???
运行结果是这样的:
请输入您的学号:1
Traceback (most recent call last):
File "C:\Users\86198\AppData\Local\Programs\Python\Python37\p23.py", line 7, in <module>
print("该学生成绩为语文",list2[0],",数学",list3[0],",英语",list4[0],",总分",sum(list2[0]+list3[0]+list4[0]))
TypeError: 'int' object is not iterable
>>>
本帖最后由 jackz007 于 2020-11-13 22:18 编辑 list1=[1,2,3,4]
list2=[98,67,89,80]
list3=[100,90,83,62]
list4=[90,98,100,82]
num=eval(input("请输入您的学号:"))
if num == list1[0]:
print("该学生成绩为语文",list2[0],",数学",list3[0],",英语",list4[0],",总分",sum((list2[0] , list3[0] , list4[0])))
elif num == list1[1]:
print("该学生成绩为语文",list2[1],",数学",list3[1],",英语",list4[1],",总分",sum((list2[1] , list3[1] , list4[1])))
elif num == list1[2]:
print("该学生成绩为语文",list2[2],",数学",list3[2],",英语",list4[2],",总分",sum((list2[2] , list3[2] , list4[2])))
elif num == list1[3]:
print("该学生成绩为语文",list2[3],",数学",list3[3],",英语",list4[3],",总分",sum((list2[3] , list3[3] , list4[3])))
else:
print()
|
|