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

后端 未结 7 1133
余生分开走
余生分开走 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:26

    totalPoints is passed by value. Which means a new copy is made and that copy is manipulated in the Correct function. Since the modified totalPoints is never returned it is lost. You need something like:

    def Correct(totalPoints):
        return totalPoints += 1
    

    and call it with

    totalPoints = Correct(totalPoints)
    

    The code doesn't show the original totalPoint definition, but that should get you going in the right direction.

    0 讨论(0)
提交回复
热议问题