How do I get this program to start over in python?
Question: I believe the word is "recurse" instead of 'start over.' I've created this
program to hone my multiplication skills in the morning. I can get it to give
me a multiplication problem, but how do I get it to ask me another one?

    
    
    from random import randint
    
    print 'Good Morning Pete!'
    
    X = randint(0, 10)
    
    Y = randint(0, 10)
    
    A = X * Y
    
    Z = int(raw_input('%i * %i = ? ' % (X, Y)))
    
    count = 0
    
    if Z == A:
        count += 1
        print 'Good Job!'
    else:
        print 'Sorry!'
    
    
    if count == '10':
        print 'Time to kill \'em'
    

how do I get it to spit out a new problem for me to solve? I'm a beginner.
Thanks all!


Answer: Pete, you wouldn't need _recursion_ in this case, but merely a _loop_.

I suggest you put the bulk of the logic of this program (the part that asks
the multiplcation problem and check your answer), into a function. Say One
Problem(). This function could return 0 if you answered wrong, 1 if you
answered correctly and -1 if you entered some key indicating that you want to
stop. (BTW, this function is introduced to help you structure the program,
make it more readeable but it is not needed for introducing a loop. you could
well keep all this stuff inside the loop. Also, you should know that there are
other loop constructs in python, for exampe while loops.)

Then you'd just need in your main section something like that :

    
    
    GoodReplyCtr = 0
    for i in range(0, 10):  # or 100 or 1000 if you feel ambitious...
       cc = OneProblem()
       if cc < 0:
            break
       GoodReplyCtr += cc
    
    print(GoodReplyCtr)
    

The concept of recursion (again not needed here), is when a function calls
itself. This is a common practice when navigating graphs (like say the
directory structure on you drive C:), or with some mathematical problems. We
typically do not need to cover recursion early in the learning of computer
languages concepts, but once you have a good mastery of things, you may find
it quite useful (and challenging at time ;-) )

Keep at it! Math and python are cool.

**Edit** : One last trick:

You may find that you need to work on some multiplication tables more than
other. Rather than using randint you can use the random's module
random.choice() method to favor some numbers or to eliminate others. for
example

    
    
    import random
    X = random.choice((2, 3, 4, 6, 7, 8, 9, 7, 9))  # see, no 0, 1,or 5 but more chance to get 7 or 9
    

