ModdersCentral

Full Version: Python Advanced Quiz
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
class Quiz():
    def __init__(self):
        self.stack = list()
        self.keys = {'a':1,'b':2,'c':3,'d':4}
    def addquestion(self,question,an1,an2,an3,an4,correctans):
        self.stack.append([question,an1,an2,an3,an4,correctans])
        return 0
    def show(self):
        for i in range(len(self.stack)):
          print(self.stack[i][0],"?")
          print("******************")
          print("A) " + self.stack[i][1])
          print("B) " + self.stack[i][2])
          print("C) " + self.stack[i][3])
          print("D) " + self.stack[i][4])
          res = str(raw_input(""))[0]
          print(res)
          if self.stack[i][self.keys[res]] == self.stack[i][5]:
            print("done")
          else:
            print("fail")

            

myStack = Quiz()
myStack.addquestion("question","answer1","answer2","answer3","answer4","correctanswer")
myStack.addquestion("hello","an1","an2","an3","an4","an3")
myStack.show()
www.000webhost.com