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:09

    totalPoints is being cloned inside your function. To do what you want, you should set totalPoints based on the function result, like so:

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

    This ignores why you would want such a function in the first place, but it should work.

提交回复
热议问题