脚本不增加变量

时间:2016-07-05 14:11:14

标签: python python-2.7 variables while-loop

我正在计算大学年终结果的整体结果。我遇到了一些问题,即totalCreditsuserCredits变量没有递增,因此我的else语句总是被返回。

""" Python University Grade Calculator """
def main():
    totalCredits = 0
    userCredits = 0
    noOfModules = int(raw_input("How many modules do you wish to add? "))
    while noOfModules > 0:
        mod_worth = int(raw_input("How many credits is the module worth? "))
        totalCredits += mod_worth
        mod_user_percentage = int(raw_input("What was your overall percentage for this module? "))
        mod_user_mark = mod_worth * (mod_user_percentage/100)
        userCredits += mod_user_mark
        noOfModules -= 1
    user_percentage = (userCredits/totalCredits) * 100
    print "You earned a total of %i out of %i credits." %(userCredits, totalCredits)
    if user_percentage > 70:
        print "This resulted in a 1st for this University year!"

    elif user_percentage > 65:
        print "This resulted in a 2:1 for this University year!"

    elif user_percentage > 60:
        print "This resulted in a 2:2 for this University year!"

    else:
        print "You have unfortunately failed this year."

main()

0 个答案:

没有答案