Advertisement
LusyanTheWhys

OOP

Apr 8th, 2017
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. class Question(object): # set methods present
  2.     def __init__(self):
  3.         pass  
  4.     def SetQuestion(self,To=None,Q=None,T=None,M=0,A=None): #initialising parameters
  5.         self._Topic=To
  6.         self._QuestionID=Q
  7.         self._Text=T
  8.         self._Mark=M
  9.         self._Answer=A
  10.     def GetQuestion(self): #outputs questionID with text of a particular question
  11.         print(self._QuestionID)
  12.         print(self._Text)
  13.     def GetMarks(self): #prints marks allocated for a particular question
  14.         print(self._Mark)
  15.     def GetTopic(self): #prints the topic of a particular question
  16.         print(self._Topic)
  17.     def GetAnswer(self): #prints the answer for a particular question
  18.         print(self._Answer)
  19. class Test(object):
  20.     def __init__(self): #set methods present
  21.         pass
  22.     def DesignTest(self,T=None,L=None,D=None,QuestList=[Question for i in range(10)]): #initialising parameters
  23.         self._TestID=T
  24.         self._DateSet=D
  25.         self._Level=L
  26.         self._Questions=QuestList
  27.         self._Number=len(Questions)
  28.         self._MaxMarks=0
  29.         for Q in self._Questions: #calculates total marks for a question paper
  30.            self._MaxMarks+=Q._Mark
  31.     def PrintTest(self): #prints test data
  32.         print("Test:\t",self._TestID)
  33.         print("Date Set:\t",self._DateSet)
  34.         print("Level set:\t",self._Level,"\n")
  35.         print("Number of questions:\t",self._Number)
  36.         print("Total marks available:\t",self._MaxMarks,"\n")
  37.         for i in range(self._Number): #prints daa for individual questions
  38.             print("Question ID:\t",self._Questions[i]._QuestionID)
  39.             print("Question body:\t",self._Questions[i]._Text)
  40.             print("Marks allocated:\t",self._Questions[i]._Mark,"\n")
  41.     def PrintAnswers(self):
  42.         for i in range(self._Number):
  43.             print(self._Questions[i]._Answer)
  44.            
  45. def CreateQuestion(QObject): #Procedure to create instance of class question
  46.     QuestionID=input("Enter question ID:")
  47.     Topic=input("Enter question topic:")
  48.     Text=input("Enter question text:")
  49.     Answer=input("Enter answer for question:")
  50.     while True: #Exception handling for mark
  51.         try:
  52.             Mark=input("Enter appropriate mark for question:")
  53.             Mark=int(Mark)
  54.             break
  55.         except ValueError:
  56.             print("Mark entered is not and integer please try again")
  57.     QObject.SetQuestion(Topic,QuestionID,Text,Mark,Answer)
  58.    
  59. def CreateTest(TObject,QuestList=[Question for i in range(10)]):
  60.     TestID=input("Enter test ID:")
  61.     Level=input("enter level (A or S or G):")
  62.     while (Level=="A") or (Level=="S") or (Level=="G"):
  63.         break #Allow process to continue
  64.     else:
  65.         print("Level invalid, please re-input")
  66.         Level=input("enter level (A or S or G):")
  67.     Date=input("Enter the date the test was set in format dd/mm/yyyy:")
  68.     TObject.DesignTest(TestID,Level,Date,QuestList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement