Python 2.7练习 要求不能使用内建sum函数,也不能使用list列表,请大神指教

Python 2.7练习

要求不能使用内建sum函数,也不能使用list列表,请大神指教

score=int(raw_input("Enter a score(enter 0 to stop):"))
total=0.0
num=0
average=0
while score!=0:
    num+=1
    total+=score
    score=int(raw_input("Enter a score(enter 0 to stop):"))
if num!=0:
    average=total/num
print "The average is %.2f"%average

温馨提示:答案为网友推荐,仅供参考
相似回答