Creating and answering a risk questionnaire
Let’s begin by creating a few useful objects that we can use to structure a questionnaire. This will be a simple static example. In reality, you may choose to store your questions in a spreadsheet, database, or file instead:
class RiskQuestion: def __init__(self, questionText, weight=1): self.questionText = questionText self.weight = weight self.answers = [] class RiskQuestionAnswer: def __init__(self, answerText, score, selected=False): self.answerText = answerText self.score = score self.selected = selected class RiskQuestionnaire: def __init__(self): self.questions = []
These three classes that we’ve just defined work together to produce what we need. The RiskQuestion
class includes a list of answers for risk questions...