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

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

    I think you mix local and global namespaces. If you change your Correct(totalPoints) to this:

    def Correct(totalPoints):
        return totalPoints + 1
    

    and in your "main code":

    print Correct(totalPoints)
    

    to

    totalPoints = Correct(totalPoints)
    print "You have", totalPoints, "points"
    

    it should work.

    Hope this helps!

提交回复
热议问题