started to learn python yesterday and found http://www.daniweb.com/forums/post161212-13.html so i figured I'd give it a try
basic quiz, randomizes the questions and keeps track of right/wrong answers and tells you your score at the end
quiz file:http://www.daniweb.com/forums/attachment.php?attachmentid=1388&d=1126839638
after you download the file edit the last line of the code to the correct path
from re import findall
from random import randint
class Quiz:
w = r = t = 0
def __init__(self, f):
h = open(f)
self.q = []
for a in findall("([A-D])\n(.+)\n(.+)\n(.+)\n(.+)\n(.+)\n?",h.read()):
self.q.append(a)
self.shuffle()
h.close()
def shuffle(self):
s = []
for x in self.q:
s.insert(randint(0,len(s)), x)
self.q = s
def start(self):
for q in self.q:
rans = q[0].upper()
b = 1
print "Question", str(self.t+1) + ":", q[1]
for x in "ABCD":
b += 1
print x + ".", q[b]
ans = raw_input("Answer: ")
if ans.upper() != rans: self.w += 1
else: self.r += 1
self.t += 1
print ""
print "End of Quiz!"
print "you answered", str(self.r), "out of", str(self.t), "questions right! (" + str(round((float(self.r)/float(self.t))*100,2)) + "%)"
pa = raw_input("Play again(y/n)? ")
if pa.lower() == "y":
self.w = self.r = self.t = 0
self.shuffle()
self.start()
quiz = Quiz("PATH\TO\QUIZ").start()