-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeQuiz.py
More file actions
65 lines (42 loc) · 2.06 KB
/
makeQuiz.py
File metadata and controls
65 lines (42 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# This script makes 20 different quizzes from a single database.
import random
import os
# Define the database nicely
captains = {'India' : 'Virat Kohli', 'Australia' : 'Steve Smith','Bangladesh':'Mashrafe Mortaza','England':'Eoin Morgan'}
# Generate the Directories for the Quiz
currentDir = os.getcwd()
os.makedirs(os.path.join(currentDir,'Quiz'))
os.makedirs(os.path.join(currentDir,'Quiz','Quizzes'))
os.makedirs(os.path.join(currentDir,'Quiz','Answer Keys'))
quizPath = os.path.join(currentDir,'Quiz','Quizzes')
answerPath = os.path.join(currentDir,'Quiz','Answer Keys')
for index in range(20):
#Creates the folder for Quiz & Answers Files
quizFile = open(os.path.join(quizPath,'QuizNo%s.txt') %(index+1),'w')
answersFile = open(os.path.join(answerPath,'AnswerNo%s.txt')%(index+1),'w')
#Write out a "template" for the Quizzes (for details for students)
quizFile.write('Name:\n\nDate:\n\nPeriod:\n\n')
quizFile.write(('-'*20) + 'Team-Captain Quiz (Form #%s)'%(index +1) + ('-'*20))
quizFile.write('\n\n')
#Randomize the order
teams = list(captains.keys())
random.shuffle(teams)
#Loop through all the captains
for question in range(4):
#Get right and wrong answers
correctAnswer = captains[teams[question]]
wrongAnswers = list(captains.values())
del wrongAnswers[wrongAnswers.index(correctAnswer)]
wrongAnswers = random.sample(wrongAnswers,1)
answerOptions = wrongAnswers + [correctAnswer]
random.shuffle(answerOptions)
#Write the question and the options to the quiz file
quizFile.write('%s. Who is the captain of %s?\n'%(question+1,teams[question]))
for i in range(2):
quizFile.write('%s. %s\n' % ('AB'[i],answerOptions[i]))
quizFile.write('\n')
answersFile.write('%s.%s\n'%(question+1,'AB'[answerOptions.index(correctAnswer)]))
#Close the files
quizFile.close()
answersFile.close()
#end of script