0

So,again I'm making a tables (math tables) checker to check your answers. I've used the search but nothing I found is relevant.

def math():
    for f in range (3):
        right=0
        wrong=0
        x=10
        c=5
        p=x*c
        print x,'times',c
        v=read_number('What is the answer?')
        if p==v:
            right=right+1
            print 'You got it right!'
        else:
            wrong=wrong+1
            print 'You got it wrong.'
    for h in range (1)
        print 'You got',right,'right, and',wrong,'wrong'

The problem is, when I do this, I get the last one wrong to test it, and it says: 'You got 0 right and 1 wrong' like it's not registering the answers. What am I doing wrong?

DSM
  • 342,061
  • 65
  • 592
  • 494
  • 1
    Hint: how many times do you ask "What is the answer"? How many times do you set `right=0` and `wrong=0`? [PS: That can't be your code, there's a missing colon after `(1)`.] – DSM Feb 17 '14 at 19:11

1 Answers1

1

Looks like a scope issue to me.

def math():
    for f in range (3):
        right=0
        wrong=0

should be

def math():
    right=0
    wrong=0
    for f in range (3):

so you don't reset right and wrong for each question.

Mike Park
  • 10,845
  • 2
  • 34
  • 50