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

后端 未结 7 1136
余生分开走
余生分开走 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条回答
  •  闹比i
    闹比i (楼主)
    2021-01-27 20:14

    totalPoint must be declared as a global variable

    and make the refernece in the function so python can update that value and not creating a new variable

    def Correct(totalPoints):
        global totalPoints
        print "Correct"
        totalPoints = totalPoints+1
        print "You have", totalPoints,"points"
    

提交回复
热议问题