pls help newbie?
Scott David Daniels
scott.daniels at acm.org
Wed May 21 15:14:52 EDT 2003
Too much fun. Getting fancier:
import random, string
class Question:
def __init__(self, question, *answers):
self.question = question
self.answer = answers[0]
self.choices = list(answers)
def ask(self):
print
print self.question
random.shuffle(self.choices)
for letter, response in zip(string.lowercase, self.choices):
print "%s." % letter, response
if response == self.answer:
correct = letter
if raw_input("What do you think? ") in (correct, self.answer):
print "GOT IT"
return True
else:
print "Sorry, the answer is %s:" % correct, self.answer
return False
questions = [
Question("CHET ATKINS", "drums", "guitar", "piano"),
Question("DORIS BRASCH", "Francios van Heyningen",
"Jurie Ferreira", "Bob Borowski")
# Then:
missed = [question for question in questions
if not question.ask()]
print
print "You scored", (len(questions)-len(missed)) * 100 / len(questions)
if missed:
print 'You need to study:'
for question in missed:
print question.question, '=', question.answer
More information about the Python-list
mailing list