Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Question(object): # set methods present
- def __init__(self):
- pass
- def SetQuestion(self,To=None,Q=None,T=None,M=0,A=None): #initialising parameters
- self._Topic=To
- self._QuestionID=Q
- self._Text=T
- self._Mark=M
- self._Answer=A
- def GetQuestion(self): #outputs questionID with text of a particular question
- print(self._QuestionID)
- print(self._Text)
- def GetMarks(self): #prints marks allocated for a particular question
- print(self._Mark)
- def GetTopic(self): #prints the topic of a particular question
- print(self._Topic)
- def GetAnswer(self): #prints the answer for a particular question
- print(self._Answer)
- class Test(object):
- def __init__(self): #set methods present
- pass
- def DesignTest(self,T=None,L=None,D=None,QuestList=[Question for i in range(10)]): #initialising parameters
- self._TestID=T
- self._DateSet=D
- self._Level=L
- self._Questions=QuestList
- self._Number=len(Questions)
- self._MaxMarks=0
- for Q in self._Questions: #calculates total marks for a question paper
- self._MaxMarks+=Q._Mark
- def PrintTest(self): #prints test data
- print("Test:\t",self._TestID)
- print("Date Set:\t",self._DateSet)
- print("Level set:\t",self._Level,"\n")
- print("Number of questions:\t",self._Number)
- print("Total marks available:\t",self._MaxMarks,"\n")
- for i in range(self._Number): #prints daa for individual questions
- print("Question ID:\t",self._Questions[i]._QuestionID)
- print("Question body:\t",self._Questions[i]._Text)
- print("Marks allocated:\t",self._Questions[i]._Mark,"\n")
- def PrintAnswers(self):
- for i in range(self._Number):
- print(self._Questions[i]._Answer)
- def CreateQuestion(QObject): #Procedure to create instance of class question
- QuestionID=input("Enter question ID:")
- Topic=input("Enter question topic:")
- Text=input("Enter question text:")
- Answer=input("Enter answer for question:")
- while True: #Exception handling for mark
- try:
- Mark=input("Enter appropriate mark for question:")
- Mark=int(Mark)
- break
- except ValueError:
- print("Mark entered is not and integer please try again")
- QObject.SetQuestion(Topic,QuestionID,Text,Mark,Answer)
- def CreateTest(TObject,QuestList=[Question for i in range(10)]):
- TestID=input("Enter test ID:")
- Level=input("enter level (A or S or G):")
- while (Level=="A") or (Level=="S") or (Level=="G"):
- break #Allow process to continue
- else:
- print("Level invalid, please re-input")
- Level=input("enter level (A or S or G):")
- Date=input("Enter the date the test was set in format dd/mm/yyyy:")
- TObject.DesignTest(TestID,Level,Date,QuestList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement