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

后端 未结 7 1134
余生分开走
余生分开走 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.

提交回复
热议问题