Python 未附加到列表中的项目
此程序未保存列表中附加的内容。当它出来时,不要存储列表中的号码Python 未附加到列表中的项目,python,list,append,python-3.8,Python,List,Append,Python 3.8,此程序未保存列表中附加的内容。当它出来时,不要存储列表中的号码 def marks(): mark=int(input("ENTER YOUR MARKS = ")) T=int(input("ENTER TOTAL MARKS")) hold=[11]#TO STORE MARKS SCORED total=[16]#TO STORE TOTAL MARKS hol
def marks():
mark=int(input("ENTER YOUR MARKS = "))
T=int(input("ENTER TOTAL MARKS"))
hold=[11]#TO STORE MARKS SCORED
total=[16]#TO STORE TOTAL MARKS
hold.append(mark)
total.append(T)
p=(sum(hold)/sum(total))*100
print('YOUR AVERAGE PERCENTAGE = ' ,p,"\n" ,
hold, total)
我希望此代码存储附加在其中的值。如果每次都要声明列表,则需要在全局范围内声明列表,以便每次调用函数标记()时不会重置其中的数据
hold=[11]#TO STORE MARKS SCORED
total=[16]#TO STORE TOTAL MARKS
def marks():
mark=int(input("ENTER YOUR MARKS = "))
T=int(input("ENTER TOTAL MARKS"))
hold.append(mark)
total.append(T)
p=(sum(hold)/sum(total))*100
print('YOUR AVERAGE PERCENTAGE = ' ,p,"\n" ,hold, total)