Skip to content

Instantly share code, notes, and snippets.

@pleonex
Created December 19, 2013 09:53
Show Gist options
  • Save pleonex/8036893 to your computer and use it in GitHub Desktop.
Save pleonex/8036893 to your computer and use it in GitHub Desktop.
Script para realizar prueba de exámenes tipo test.
#!/usr/bin/python
'''
do_quiz.py is a script to read and test true/false questions.
Questions in the external file must have the following format:
X. Question T
where 'X' is a unique question number, 'Question' is the question and
'T' is the question result.
Copyright (C) 2013 Benito Palacios (benito356@gmail.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import random
FILE = "Quiz2.txt"
def get_quiz(file_path):
f = open(file_path, 'r')
quiz = {}
for line in f:
line = line.strip()
if len(line) < 3:
continue
elif line[1] == '.':
num = int(line[0])
elif line[2] == '.':
num = int(line[0:2])
else:
continue
answer = line[-1]
question = line[len(str(num))+1 : -2]
question = question.strip()
quiz[num] = [question, answer]
return quiz
quiz = get_quiz(FILE)
tries = 0
while len(quiz) > 0:
tries += 1
bads = {}
nums = quiz.keys() # Gets keys and ...
random.shuffle(nums) # ... unsorts them
print "------------------------------"
print "Number of tries:", tries
print "Questions left: %d" % len(quiz)
print "------------------------------"
print
# Asks each question
for n in nums:
question = quiz[n][0]
answer = quiz[n][1]
ans = raw_input(str(n) + ': ' + question + ' ').upper()
if ans == answer:
print "\tOk!"
else:
bads[n] = quiz[n] # Adds to the repeat question list
print "\tBad..."
# Shows status
print len(bads), "/", len(quiz), "->",
print ( 1 - float(len(bads))/len(quiz) ) * 10
# Gets the quiz
quiz = bads
print
raw_input("Press any key to quit. . .")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment