I have this function that is supposed to count points but it doesn't add them

后端 未结 7 1218
余生分开走
余生分开走 2021-01-27 19:55

I have this function that is supposed to count points but it doesn\'t add them:

def Correct(totalPoints):
    print \"Correct\"
    totalPoints = totalPoints+1
          


        
7条回答
  •  天命终不由人
    2021-01-27 20:17

    1) you're not returning the value from the function 2) global variables are best changed outside of functions - outside of the function, set the variable equal to whatever the function returns or - if you MUST do it inside the function, you want to declare it to be global at the beginning of the function.

    def Correct(totalpoints):
        return totalpoints += 1
    

    ......

    if NBAANSWER == NBA2[NBAQues]:
        print "Correct!"
        totalpoints = Correct(totalPoints)
        print "You have ", totalpoints, "points"
    

提交回复
热议问题