Last active
November 3, 2016 05:29
-
-
Save kemingy/e4325ead29155554b8fe618502c20aed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf-8 | |
import random | |
import sys | |
def get_quiz(num=10, inf=0, sup=20): | |
quiz = [] | |
while len(quiz) < num: | |
r = random.random() | |
x = random.randint(inf, sup) | |
y = random.randint(inf, sup) | |
if r < 0.25: | |
q = str(x) + ' + ' + str(y) | |
elif r < 0.5: | |
if x < y: x, y = y, x | |
q = str(x) + ' - ' + str(y) | |
elif r < 0.75: | |
q = str(x) + ' x ' + str(y) | |
else: | |
q = str(x * y) + ' / ' + str(y) | |
quiz.append(q) | |
return quiz | |
if __name__ == '__main__': | |
if len(sys.argv) == 2: | |
quiz = get_quiz(int(sys.argv[1])) | |
else: | |
quiz = get_quiz() | |
for q in quiz: | |
print "{}:\t{}".format(quiz.index(q) + 1, q) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment