vendredi 19 juin 2015

Import functions in randomized order in Python

I've already created modules containing functions that drill different mental math techniques by randomly generating certain kinds of problems. What I want to do is make a review program that imports 5 problems from each module, but in a random order.

Here's an example of one of the modules:

import random

class font:
    underline = '\033[4m'
    end = '\033[0m'

def eleven(problems):

    for i in range(problems):
    num1 = random.randint(10,99)
    answer = num1 * 11

    print "\n    %d" % num1
    print "  " + font.underline + "x 11" + font.end

    raw_input()

    if answer >= 1000:
        pad = " " 
    else:
        pad = "  "

    print pad, answer

I've run several searches both on Google and on this site, but I couldn't find anything directly relevant. Part of the problem is I might not recognize a solution if it was staring me in the face, knowing as little as I do about Python. Ideally I would wade through the documentation and find my own answer, but I was hoping someone could at least point me in the right direction.

Thanks.




Aucun commentaire:

Enregistrer un commentaire