Advertisement
jabela

ObjectOrientedVersion3.1

Jan 20th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1. import datetime
  2. #To enable us to set the date
  3.  
  4. class Tesj:
  5.     def __init__(self,TesjID):
  6.         self.__TesjID = TesjID
  7.         self.__questions = []
  8.         self.__NumberOfQuestions = 0
  9.         self.__MaxMarks = 0
  10.         self.__Level = None
  11.         self.__DateSet = datetime.datetime.now()
  12.  
  13.     def DesignTesj(self):
  14.         #Set level for Tesj
  15.         while True:
  16.             level = input("Set Tesj level (A, S, G):")
  17.             if level.upper() in ["A","S","G"]:
  18.                 self.__level = level
  19.                 break
  20.             else:
  21.                 print("Wrong level code")
  22.  
  23.         while True:
  24.             if self.__NumberOfQuestions < 10:
  25.                 yn = input("Do you wish to add a question?")
  26.  
  27.                 if yn.upper() == "Y":
  28.                     #Generate question id based on Tesj id and question number
  29.                     newQID = self.__TesjID + str(self.__NumberOfQuestions)
  30.                     #Create question object
  31.                     newQuestion = Question(newQID)
  32.                     #Setup the question
  33.                     newQuestion.setQuestion()
  34.                     #Add the marks to the max marks
  35.                     self.__MaxMarks += newQuestion.GetMarks()
  36.                     #Link the question to my list (array)
  37.                     self.__questions.append(newQuestion)
  38.  
  39.                     self.__NumberOfQuestions += 1
  40.                 else:
  41.                     break
  42.             else:
  43.                 break
  44.  
  45.     def PrintTesj(self):
  46.  
  47.         for question in self.__questions:
  48.             print(question.getQuestion())
  49.  
  50.     def PrintAnswers(self):
  51.         for question in self.__questions:
  52.             print(question.GetAnswer())
  53.  
  54. class Question:
  55.     def __init__(self,QuestionID):
  56.         self.__QuestionID = QuestionID
  57.         self.__QuestionText = ""
  58.         self.__Answer = ""
  59.         self.__Marks = 0
  60.         self.__Topic = ""
  61.  
  62.     def setQuestion(self):
  63.         questionText = input("Enter question text: ")
  64.         self.__QuestionText = questionText
  65.  
  66.         answer = input("Enter the answer: ")
  67.         self.__Answer = answer
  68.         while True:
  69.             marks = input("Enter the marks: ")
  70.  
  71.             try:
  72.                 marks = int(marks)
  73.                 break
  74.  
  75.             except ValueError:
  76.                 print("Not a number")
  77.  
  78.         self.__Marks = marks
  79.  
  80.         topic = input("Enter the topic: ")
  81.         self.__Topic = topic
  82.  
  83.     def getQuestion(self):
  84.         return self.__QuestionText
  85.  
  86.     def GetMarks(self):
  87.         return self.__Marks
  88.  
  89.     def GetTopic(self):
  90.         return self.__Topic
  91.  
  92.     def GetAnswer(self):
  93.         return self.__Answer
  94.  
  95.  
  96. Tesj = Tesj("JA")
  97. Tesj.DesignTesj()
  98. Tesj.PrintTesj()
  99. input()
  100. Tesj.PrintAnswers()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement