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

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

    You are not returning the function output. It should be

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

    You should now return the correct value to the main function. You should also fix the indentation to be correct. You need to show where totalPoints was defined.

        elif answer == 'nba':
            NBAQues = random.randint(0,len(NBA1)-1)
        # Is this the way you meant it to be indented?
        NBAVar = NBA1[NBAQues]
    
        print NBAVar
        NBAAnswer = raw_input()
        NBAAnswer = NBAAnswer.lower()
        if NBAAnswer == NBA2[NBAQues]:
            # Make sure totalPoints was initialized properly
            totalPoints = Correct(totalPoints)
            print totalPoints
        elif NBAAnswer != NBA2[NBAQues]:
            print "False. The correct answer was", NBA2[NBAQues]
            NBA1.remove(NBAVar)
            NBA2.remove(NBA2[NBAQues])
            print "Choose another."
    

提交回复
热议问题