Python 编写子例程的不同方法

Python 编写子例程的不同方法,python,subroutine,Python,Subroutine,是否有另一种方法来编写这个带有验证的子例程,或者是一种更无组织的方法 months=['January','February','March','April','May','June','July','August','September','October','November','December'] total=0 student=input('Enter new name: ') for x in range (12): score=float(input('Enter scor

是否有另一种方法来编写这个带有验证的子例程,或者是一种更无组织的方法

months=['January','February','March','April','May','June','July','August','September','October','November','December']
total=0
student=input('Enter new name: ')
for x in range (12):
    score=float(input('Enter score for ' + months [x] + ' out of 10: '))
    while score > 10 or score <1 or score %1 != 0 :
        float(score=input('Invalid','Enter score for' + months [x]+'out of 10: '))
        total=total+score
        print('Your total Score is', total)
        names.update[{name:totalscore}]
months=[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”]
总数=0
student=输入('输入新名称:')
对于范围(12)内的x:
分数=浮动(输入('在10个月中输入'+个月[x]+'的分数:'))

虽然分数>10或分数总是有一种更无组织的方式,但我不编辑该部分,以防万一这是OP真正想要的。此代码实际上从未定义
totalscore
的值,因此编写时它不应该起作用,嗯,这里发生了什么:
names.update[{name:totalscore}]