Example #1
0
    def add_default_questions(self):
        """add default questions"""

        q1 = Question(
            'LoL',
            'How is Laughing out Loud shortned?',
            '')

        q2 = Question(
            'Cartman',
            "In South Park, what is Eric's last name?",
            '')

        q3 = Question(
            'Bartz',
            'Who is the main character of "Final Fantasy V"?',
            '')

        q4 = QuestionRadio(
            'Clancy',
            'In "The Simpsons" what is the first name of Chief Wiggum?',
            ('David', 'Bart', 'Clancy', 'Arthur'))

        q5 = QuestionRadio(
            'Barry Trotter',
            '"Bored of the Rings" is a parody of "Lord of the \
            Rings". "Harry Potter" has a similar parody in almost \
            the same style. What is the title of this book? ', \
            ('Arry Halfmass', 'Derek Otter', 'Carry on Potter', \
            'Barry Trotter'))

        q6 = QuestionRadio(
            'Capricciosa',
            'How do you spell the pizza with salami and mushrooms?',\
            ('Capprichiosa', 'Caprisiosa', 'Capricciosa'))

        q7 = QuestionCheck(
            'Gul Richard',
            "Which ones are swedish apples?",
            ('Anna Book', 'Funny', 'Gul Richard', 'Crisps', 'Yummy', ))

        q8 = QuestionCheck(
            'Batman',
            "Superheroes?",
            ('Batman', 'Catman', 'Fatman', 'Hatman', 'Chatman', ))

        q9 = QuestionCheck(
            'Algeria',
            "The tenth biggest country in the world (Area)?",
            ('China', 'Algeria', 'Kazakhstan', 'Australia', 'India', 'Russia'))

        self.questions.append(q1)
        self.questions.append(q2)
        self.questions.append(q3)
        self.questions.append(q4)
        self.questions.append(q5)
        self.questions.append(q6)
        self.questions.append(q7)
        self.questions.append(q8)
        self.questions.append(q9)
Example #2
0
def ask():
    result = request.form

    q = Question.new_question(session['user_id'])
    q.question = result['question']
    q.asker = result['asker']
    q.save()

    return redirect(url_for('index'))
Example #3
0
    def _list_questions(self):
        """Load every question into this class"""

        # This is done every time, it shouldnt be.
        # It could be, so long as the order is the same
        # every time...

        # pdb.set_trace()
        local_list = []
        jdata = json.load(open("questions.json", encoding="utf-8"))

        # for quest in jdata.keys():
        for i, quest in enumerate(jdata):
        # for i in jdata.
            # pp = pprint.PrettyPrinter(indent=4)
            # pp.pprint(jdata)
            # print("jdata - nyckel " + quest)

            txt = jdata[quest]["question"]
            switch = jdata[quest]["type"]
            answ = jdata[quest]["answer"]
            number = quest

            # print(number)

            if switch == "radiobutton":
                alts = jdata[quest]["alt"]
                new_obj = RadiobuttonQuestion(number, txt, answ, alts)
            elif switch == "checkbox":
                alts = jdata[quest]["alt"]
                new_obj = CheckboxQuestion(number, txt, answ, alts)
            else:
                new_obj = Question(number, txt, answ)

            # print(quest)
            # print(type(quest))
            # print(type(new_obj))

            # pdb.set_trace()

            local_list.append(new_obj)

        # pp = pprint.PrettyPrinter(indent=4)
        # pp.pprint(local_list)

        local_list.sort(key=lambda quest_obj: quest_obj.get_number())

        # print(local_list)

        self._last_question = len(local_list)
        # pdb.set_trace()
        # print("Antal frågor: {}".format(self._last_question))
        return local_list
Example #4
0
def main():
    first = Question()
    first.setText("Who was the inventor of Python?")
    first.setAnswer("Guido van Rossum")

    second = ChoiceQuestion()
    second.setText("In which country was the inventor of Python born?")
    second.addChoice("Australia", False)
    second.addChoice("Canada", False)
    second.addChoice("Netherlands", True)
    second.addChoice("United States", False)

    third = NumericQuestion()
    third.setText("How much is 1 + 1")
    third.setAnswer("2")

    fourth = FillInQuestion()
    fourth.setText("The inventor of Python was _____")
    fourth.setText4("The inventor of Python was")
    fourth.setAnswer("Guido van Rossum")

    fifth = MultiChoiceQuestion()
    fifth.setText("In which fruit is red?")
    fifth.addMultiChoice("Apple", True)
    fifth.addMultiChoice("Orange", False)
    fifth.addMultiChoice("Tomato", True)
    fifth.addMultiChoice("guava", False)

    #presentQuestion(first)
    #presentQuestion(second)
    present3Question(third)
    present4Question(fourth)
    present5Question(fifth)
Example #5
0
def GenerateQuestionList():
    q_list = []

    q_list.append(
        Question("How many days are in a lunar year?", "354", "365", "243",
                 "379", 1))
    q_list.append(
        Question("What is the largest planet?", "Mars", "Jupiter", "Earth",
                 "Pluto", 2))
    q_list.append(
        Question("What is the largest kind of whale?", "Orca whale",
                 "Humpback whale", "Beluga whale", "Blue whale", 4))
    q_list.append(
        Question("Which dinosaur could fly?", "Triceratops",
                 "Tyrannosaurus Rex", "Pteranodon", "Diplodocus", 3))
    q_list.append(
        Question("Which of these Winnie the Pooh characters is a donkey?",
                 "Pooh", "Eeyore", "Piglet", "Kanga", 2))
    q_list.append(
        Question("What is the hottest planet?", "Mars", "Pluto", "Earth",
                 "Venus", 4))
    q_list.append(
        Question("Which dinosaur had the largest brain compared to body size?",
                 "Troodon", "Stegosaurus", "Ichthyosaurus", "Gigantoraptor",
                 4))
    q_list.append(
        Question("What is the largest type of penguins?", "Chinstrap penguins",
                 "Macaroni penguins", "Emperor penguins",
                 "White-flippered penguins", 3))
    q_list.append(
        Question("Which children's story character is a monkey?",
                 "Winnie the Pooh", "Curious George", "Horton", "Goofy", 2))
    q_list.append(
        Question("How long is a year on Mars?", "550 Earth days",
                 "498 Earth days", "126 Earth days", "687 Earth days", 4))

    return q_list
Example #6
0
    def __getQuestionsList(self):
        questions_tdb = json.loads(self.__requestQuestions())
        questions_tdb = questions_tdb['results']

        unescape = html.unescape

        for question_dict in questions_tdb:
            category = unescape(question_dict['category'])
            question = unescape(question_dict['question'])
            correct_ans = unescape(question_dict['correct_answer'])
            wrong_ans = unescape(question_dict['incorrect_answers'])

            self.__QUESTION_LIST.append(Question(category, question, correct_ans, wrong_ans))

        return True
Example #7
0
def get_questions(data_from_opentdb):   
    questions_tdb = json.loads(response.text)
    questions_tdb = questions_tdb["results"]

    unescape = html.unescape

    question_list = []

    for question_dict in questions_tdb:
        category = unescape(question_dict["category"])
        question = unescape(question_dict["question"])
        correct_ans = unescape(question_dict["correct_answer"])
        wrong_ans = unescape(question_dict["incorrect_answers"])

        question_list.append(Question(category, question, correct_ans, wrong_ans))
    
    return question_list
def main() :
   first = Question()
   first.setText("Who was the inventor of Python?")
   first.setAnswer("Guido van Rossum")

   second = ChoiceQuestion()
   second.setText("In which country was the inventor of Python born?")
   second.addChoice("Australia", False)
   second.addChoice("Canada", False)
   second.addChoice("Netherlands", True)
   second.addChoice("United States", False)

   presentQuestion(first)
   presentQuestion(second)
Example #9
0
 def test_is_correct_answer_substring(self):
     self.t.q = Question("Test category", "Test question?", "Test #answer#",
                         None)
     assert (self.t.is_correct_answer("answer"))
Example #10
0
def vote(id):
    q = Question.get(id)
    q.vote_toggle(session['user_id'])

    return redirect(url_for('index'))
Example #11
0
def delete(id):
    q = Question.get(id)
    q.delete()

    return redirect(url_for('index'))
Example #12
0
def generate_bank():
    for i in question_data:
        new_q = Question(i['question'], i['correct_answer'])
        question_bank.append(new_q)
    return question_bank
Example #13
0
def index():
    return render_template('index.html', questions=Question.active())
Example #14
0
        Checks if guessed answer is the correct answer
        """
        question = self._questions[self._quest_count]
        if question.get_type() == "checkbox":
            response = form.getlist("answer")
            for resp in response:
                if question.check_answer(resp):
                    self._points += 1
        else:
            response = form["answer"]
            if question.check_answer(response):
                self._points += 1

        self._quest_count += 1

q1 = Question("djungelboken",\
 "Vad heter den animerade filmen från 1967 som handlar om Mowgli?")
q2 = Question("merkurius", "Vilken planet ligger närmast solen?")
q3 = Question("vänster", \
"Springer älgen, på Vägverkets varningsskylt för älg, åt vänster eller höger?")
q4 = CheckboxQuestion(["K2", "Mount Everest", "Kanchenjunga"], \
"Vilka av följande berg är världens 3 högsta?", \
["K2", "Lhotse", "Mount Everest", "Makalu", "Kanchenjunga", "Cho Oyu"])
q5 = CheckboxQuestion(["Kanel", "Ingefära", "Nejlika"], \
"Vilka kryddor använder man när man bakar pepparkakor?", \
["Peppar", "Kardemumma", "Kanel", "Ingefära", "Nejlika", "Vanilj"])
q6 = CheckboxQuestion(["Maja", "Alice", "Julia"], \
"Vilka var de tre mest populära flicknamnen under 2010?", \
["Julia", "Maja", "Lisa", "Johanna", "Alicia", "Alice"])
q7 = RadiobuttonQuestion("narkos", \
 "2019 godkändes ett nytt antidepressivt läkemedel. Vad har det använts vid \
 tidigare?", ["Narkos", "Kejsarsnitt", "Benbrott"])
Example #15
0
    def start(self):

        T = Result('Produkt ist nicht aus der Richtlinie ausgenommen \n', True)
        F = Result('MRL trifft nicht zu! \n', False)
        """
		MRL_M Exceptions
		"""
        q1_mrl_E = Question(
            'Handelt es sich bei dem Produkt um eines der Folgenden Erzeugnisse?'
        )
        q1_mrl_E.text += MRLExceptions

        q1_mrl_E.posChild = F
        q1_mrl_E.negChild = T
        """
		Maschine vs Unvollstaendige Maschine
		"""

        q1_mrl_M = Question(
            'Besteht das Erzeugniss aus miteinander Verbundenen Teilen?')

        q2a_mrl_M = Question('Ist mindestens ein Teil davon beweglich?')

        q2b_mrl_M = Question('Teile nur zu Transportzwecken getrennt?')

        q3_mrl_M = Question(
            'Kann das Erzeugniss fuer sich genommen die bestimmte Funktion erfuellen?'
        )

        q4a_mrl_M = Question(
            'Ist das Produkt mit einem Antriebssystem ausgestattet?')

        q4b_mrl_M = Question(
            'Ist das Produkt zum Zusammenbau mit anderen (unvollständigen) Maschinen/Ausrüstungen gedacht?'
        )

        q5a_mrl_M = Question(
            'Das Antriebssystem ist die unmittelbar eingesetzte menschliche Kraft?'
        )
        q5b_mrl_M = Question('Fuer ein Antriebssystem vorgesehen?')
        q5c_mrl_M = Question('Ist das Produkt fast eine Maschine?')

        q6a_mrl_M = Question('Ist das Antriebssystem genau spezifiziert?')
        q6b_mrl_M = Question(
            'Handelt es sich um ein Produkt fuer Hebevorgaenge?')
        q6b_mrl_M_IV = Question(
            'Findet sich das Produkt in folgender Liste wider?:' + MRLAnhangIV)

        q6b_mrl_M_harm = Question(
            'Ist die Maschine nach einer harmonisierten Norm hergestellt worden und berücksichtigen diese Normen alle relevanten grundlegenden Sicherheits- und Gesundheitsschutzanforderungen?'
        )

        q6c_mrl_M = Question(
            'Das Antriebssystem ist die unmittelbar eingesetzte tierische Kraft?'
        )

        q7a_mrl_M = Question(
            'Ist eine Verbindung zum Einsatzort, oder zur Energie- bzw. Antriebsquelle vorhanden?'
        )

        q8a_mrl_M = Question(
            'Produkt ist zur Anbringung auf einem Fahrzeug / in einem Gebäude gedacht?'
        )

        q9a_mrl_M = Question(
            'Produkt ist Einbaufertig für die Anbringung auf einem Fahrzeug / in einem Gebäude?'
        )
        q9b_mrl_M = Question(
            'Handelt es sich bei dem Produkt um miteinander verbundene Maschinen/unvollständige Maschinen?'
        )

        q10a_mrl_M = Question(
            'Ist eine Funktionale bzw. Steuerungs- order Sicherheitstechnische Verbindung vorhanden?'
        )

        q1_mrl_M.posChild = q2a_mrl_M
        q1_mrl_M.negChild = q2b_mrl_M

        q2a_mrl_M.posChild = q3_mrl_M
        q2a_mrl_M.negChild = F

        q2b_mrl_M.posChild = F
        q2b_mrl_M.negChild = q2a_mrl_M

        q3_mrl_M.posChild = q4a_mrl_M
        q3_mrl_M.negChild = q4b_mrl_M

        q4a_mrl_M.posChild = q5a_mrl_M
        q4a_mrl_M.negChild = q5b_mrl_M
        q4b_mrl_M.posChild = q5c_mrl_M
        q4b_mrl_M.negChild = F

        q5a_mrl_M.posChild = q6b_mrl_M
        q5a_mrl_M.negChild = q6c_mrl_M
        q5b_mrl_M.posChild = q6b_mrl_M
        q5b_mrl_M.negChild = F
        q5c_mrl_M.posChild = self.resultUnvollstaendigeMaschine
        q5c_mrl_M.negChild = F

        q6a_mrl_M.posChild = q5a_mrl_M
        q6a_mrl_M.negChild = F

        q6b_mrl_M.posChild = q6b_mrl_M_IV
        q6b_mrl_M.negChild = self.resultKeinProdukt_a_g

        q6b_mrl_M_IV.negChild = self.resultMaschineNichtIV
        q6b_mrl_M_IV.posChild = q6b_mrl_M_harm

        q6b_mrl_M_harm.posChild = self.resultMaschineHarm
        q6b_mrl_M_harm.negChild = self.resultMaschineHarm_tw

        q6c_mrl_M.posChild = F
        q6c_mrl_M.negChild = q7a_mrl_M

        q7a_mrl_M.posChild = q8a_mrl_M
        q7a_mrl_M.negChild = self.resultVerbindung

        q8a_mrl_M.posChild = q9a_mrl_M
        q8a_mrl_M.negChild = q9b_mrl_M

        q9a_mrl_M.posChild = self.resultEinbau
        q9a_mrl_M.negChild = q4b_mrl_M
        q9b_mrl_M.posChild = q10a_mrl_M
        q9b_mrl_M.negChild = self.resultMaschineNichtIV

        q10a_mrl_M.posChild = self.resultMaschineNichtIV
        q10a_mrl_M.negChild = self.resultSchnittstelle
        """
		Auswechselbare Ausreustung
		"""
        q1_mrl_AA = Question(
            'Ist das Produkt zum Anbringen an eine (Zug-)Maschine durch den Bediener der (Zug-)Maschine gedacht?'
        )

        q2_mrl_AA = Question(
            'Ist das Produkt ein einfaches Fertigungsteil (keine beweglichen Teile), das in direkter Berührung mit dem zu bearbeiteten Gegenstand oder Werkstoff steht?'
        )

        q3a_mrl_AA = Question(
            'Ist vom Hersteller der Maschine als geeignetes Werkzeug beschrieben?'
        )
        q3b_mrl_AA = Question(
            'Produkt Ändert / Erweitert die Funktion der Maschine?')

        q1_mrl_AA.posChild = q2_mrl_AA
        q1_mrl_AA.negChild = self.resultKeineAuswAusruestung

        q2_mrl_AA.posChild = q3a_mrl_AA
        q2_mrl_AA.negChild = q3b_mrl_AA

        q3a_mrl_AA.posChild = self.resultWerkzeug
        q3a_mrl_AA.negChild = self.resultFalschesWerkzeug
        q3b_mrl_AA.posChild = self.resultAuswAusruestung
        """
		Sicherheitsbauteil
		"""
        q1_mrl_SB = Question(
            'Dient zur Gewährleistung einer Sicherheitsfunktion?')

        q2_mrl_SB = Question('Wird das Produkt gesondert in Verkehr gebracht?')

        q3_mrl_SB = Question(
            'Ausfall des Bauteils gefährdet die Sicherheit von Personen?')

        q4_mrl_SB = Question('Für das Funktionieren der Maschine Notwendig?')

        q5a_mrl_SB = Question(
            'Kann durch ein - für die reine Funktion der Maschine - übliches Bauteil ersetzt werden?'
        )

        q5b_mrl_SB = Question(
            'Wird vom Hersteller der Maschine als Ersatzteil für identisches Produkt verkauft?'
        )

        q1_mrl_SB.posChild = q2_mrl_SB
        q1_mrl_SB.negChild = self.resultKeinSicherheitsBauteil

        q2_mrl_SB.posChild = q3_mrl_SB
        q2_mrl_SB.negChild = self.resultKeinSicherheitsBauteil

        q3_mrl_SB.posChild = q4_mrl_SB
        q3_mrl_SB.negChild = self.resultKeinSicherheitsBauteil

        q4_mrl_SB.posChild = q5a_mrl_SB
        q4_mrl_SB.negChild = q5b_mrl_SB

        q5a_mrl_SB.posChild = q5b_mrl_SB
        q5a_mrl_SB.negChild = self.resultKeinSicherheitsBauteil
        q5b_mrl_SB.posChild = self.resultAusgeschlossenesSicherheitsBauteil
        q5b_mrl_SB.negChild = self.resultSicherheitsBauteil
        """
		Lasten 
		"""
        q1_mrl_L = Question('Dient zum Ergreifen einer Last?')

        q2_mrl_L = Question(
            'Ist Bestandteil des Hebezeugs / Lastaufnahmemittels?')

        q3a_mrl_L = Question('Ist Kette, Seil oder Gurt?')
        q3b_mrl_L = Question(
            'Ist dazu bestimmt, zwischen Last und Maschine angebracht zu werden?'
        )

        q4_mrl_L = Question(
            'Ist dazu bestimmt, an der Last angebracht zu werden?')

        q5_mrl_L = Question('Dazu bestimmt, Bestandteil der Last zu werden?')

        q6_mrl_L = Question('Wird gesondert in Verkehr gebracht?')

        q1_mrl_L.posChild = q2_mrl_L
        q1_mrl_L.negChild = self.resultKeinLastenaufnahmeMittel

        q2_mrl_L.posChild = q3a_mrl_L
        q2_mrl_L.negChild = q3b_mrl_L

        q3a_mrl_L.posChild = self.resultKetten
        q3a_mrl_L.negChild = self.resultKeinLastenaufnahmeMittel

        q3b_mrl_L.posChild = self.resultLastenaufnahmeMittel
        q3b_mrl_L.negChild = q4_mrl_L

        q4_mrl_L.posChild = self.resultLastenaufnahmeMittel
        q4_mrl_L.negChild = q5_mrl_L

        q5_mrl_L.posChild = self.resultKeinLastenaufnahmeMittel
        q5_mrl_L.negChild = q6_mrl_L

        q6_mrl_L.posChild = self.resultLastenaufnahmeMittel
        q6_mrl_L.negChild = self.resultKeinLastenaufnahmeMittel
        """
		Gelenkwellen 
		"""

        q1_mrl_GW = Question(
            'Zur Kraftbertragung zwischen einer Antriebs- oder Zugmaschine und einer anderen Maschine gedacht?'
        )

        q2_mrl_GW = Question(
            'Produkt verbindet die ersten Festlager beider Maschinen?')

        q1_mrl_GW.posChild = q2_mrl_GW
        q1_mrl_GW.negChild = self.resultKeineGelenkwelle

        q2_mrl_GW.posChild = self.resultGelenkwelle
        q1_mrl_GW.negChild = self.resultKeineGelenkwelle

        t = Test()
        testResult = t.start(q1_mrl_E)

        if testResult.bool:
            testResult = t.start(q1_mrl_M)

        if testResult.bool:
            testResult = t.start(q1_mrl_AA)

        if testResult.bool:
            testResult = t.start(q1_mrl_SB)

        if testResult.bool:
            testResult = t.start(q1_mrl_L)

        if testResult.bool:
            testResult = t.start(q1_mrl_GW)

        return testResult
Example #16
0
class Zulu:
    """Zulu is a mysterious questioner, looking for an answerer"""
    q = Question(None, None)
    allquestions = q.generate_questions()
 def get_next_question(self):
     self.total_questions += 1
     self.current_question = Question.get_random()
     self.text_box['text'] = self.current_question
     self.feedback_box['text'] = ''
Example #18
0
 def test_is_correct_answer_simple(self):
     self.t.q = Question("Test category", "Test question?", "Test answer",
                         None)
     assert (self.t.is_correct_answer("Test answer"))
Example #19
0
def load_objects_from_excel(excel_path):
    INFO_SHEET_IDX = 0
    QUESTION_ROW_STEP = 5
    STIMULUS_COL = 1
    STEM_COL = 2
    ANSWERS_COL = 3
    RIGHT_ANSWER_COL = 4
    EXPLANATION_COL = 5
    NOTE_COL = 6
    TYPE_COL = 7
    SUB_TYPE_COL = 8

    wb = xlrd.open_workbook(excel_path)

    sheet = wb.sheet_by_index(INFO_SHEET_IDX)

    questions = []

    answer_map = {
        "a": 0,
        "b": 1,
        "c": 2,
        "d": 3,
        "e": 4,
        "A": 0,
        "B": 1,
        "C": 2,
        "D": 3,
        "E": 4
    }

    label_map2 = ["A", "B", "C", "D", "E"]

    for row_index in range(1, sheet.nrows, QUESTION_ROW_STEP):
        print("row_index", row_index)
        stimulus = sheet.cell(row_index, STIMULUS_COL).value
        if not stimulus or stimulus == "":
            print("Error at row: ", row_index)
            return None
        stem = sheet.cell(row_index, STEM_COL).value
        answer_choices = []
        ans_idx = 0
        for r_idx in range(row_index, row_index + QUESTION_ROW_STEP):
            ans_choice = str(sheet.cell(r_idx, ANSWERS_COL).value).strip()
            # print(re.sub("^[a-eA-E].", "", ans_choice).strip())
            explanation = sheet.cell(r_idx, EXPLANATION_COL).value
            note = sheet.cell(r_idx, NOTE_COL).value
            answer_choices.append(
                AnswerChoice(index=ans_idx,
                             choice=re.sub("^[a-eA-E].", "",
                                           ans_choice).strip(),
                             explanation=re.sub("^[a-eA-E].", "",
                                                explanation).strip(),
                             note=re.sub("^[a-eA-E].", "", note).strip()))
            ans_idx += 1

        right_answer = answer_map[str(
            sheet.cell(row_index, RIGHT_ANSWER_COL).value).strip()]
        type = sheet.cell(row_index, TYPE_COL).value
        sub_type = sheet.cell(row_index, SUB_TYPE_COL).value

        questions.append(
            Question(
                type=type,
                sub_type=sub_type,
                stimulus=stimulus,
                stem=stem,
                answer_choices=answer_choices,
                right_answer=right_answer,
            ))
        # Question(
        #     type=type,
        #     sub_type=sub_type,
        #     stimulus=stimulus,
        #     stem=stem,
        #     answer_choices=answer_choices,
        #     right_answer= right_answer
        #
    return questions
Example #20
0
from questions import Question

question_prompts = [
    "A group of Squirrels are Called?\n(a)Drury\n(b)Spike\n(c)Scarlet\n(d)Scurry\n\n",
    "A group of Monkeys are Called?\n(a)Scurry\n(b)Troop\n(c)Scree\n(d)Bunch\n\n",
    "A group of Giraffes are Called?\n(a)Tower\n(b)Prickle\n(c)Scurry\n(d)Toasters\n\n",
    "A group of Porcupines are Called?\n(a)Shoal\n(b)Troop\n(c)Prickle\n(d)Dazzle\n\n"
    "A group of Lions are Called?\n(a)Den\n(b)Lions\n(c)Pride\n(d)Prides\n\n"
]

questions = [
    Question(question_prompts[0], "d"),
    Question(question_prompts[1], "b"),
    Question(question_prompts[2], "a"),
    Question(question_prompts[3], "c"),

]


def run_test(questions):
    score = 0
    for qtn in questions:
        answer = input(qtn.prompt)
        if answer == qtn.answer:
            score += 1
    print("You Scored: " + str(score) + "/" + str(len(questions)))


run_test(questions)

 def addQuestions(self, questions, answers):
     session.add(Question(question=questions, answer=answers))
     session.commit()
# in order to use the 'Question' Class from 'questions.py' we have to import it using 'from ____ import _____'
from questions import Question  # this is saying 'from the questions.py file, import the Class called Question'

# this is an Array of the question prompts that will be in the multiple choice quiz - it called 'question_prompts'
question_prompts = [
    "For each question, enter the letter of the answer you think it is\n"
    "What colour are Apples?\n(a) Red/ Green\n(b) Purple\n(c) Orange\n\n",
    "What colour are Bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\n",
    "What colour are Strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n",
]

# here we create an Array to start creating the Objects for each question (shown above)
# we create each question (from above). [] contains the index of the question. and "" contains the answer to it
questions = [
    Question(question_prompts[0], "a"),  # [0] is the first question, "a" is the answer to the question
    Question(question_prompts[1], "c"),  # [1] is the second question, "c" is the answer to the question
    Question(question_prompts[2], "b"),  # [2] is the third question, "b" is the answer to the question
]


# we have to create a Function that will run the test i.e. ask the questions and see if they got the answer right
# we pass one Parameter, it is 'questions' (as above), this will be the list of question Objects to ask the user
def run_test(questions):
    score = 0  # we create a variable, every time the user gets an answer correct, we increment the 'score' variable

    # now we want to loop through each question, ask it, get the answer, and then check if it's right using a For Loop
    for Question in questions:  # for each 'Question' Object inside the questions Array above, we want to do something

        # this 'answer' variable stores the user's answer. we ask for the user's input, by using .prompt in the (),
        # - the programme will automatically ask the user each question from the Array we created above, one by one
Example #23
0
    def test_is_correct_answer_regex(self):
        self.t.q = Question("Test category", "Test question?",
                            "Test regex answer", "Test regex(p)? answer")

        assert (self.t.is_correct_answer("Test regex answer"))
        assert (self.t.is_correct_answer("test regexp answer"))
Example #24
0
from questions import Question

questions = [
    Question(
        "Who is the best footballer of the 21st century?\n "
        "(a)Lionel Messi (b)Zinedine Zidane (c)Cristiano Ronaldo (d) Ronaldo9\n",
        "a"),
    Question(
        "Which country has the most World cups?\n "
        "(a)Germany (b)Italy (c)Brazil (d)France\n", 'c'),
    Question(
        "Which player has the most world cup Goals?\n"
        "(a)Ronaldo9 (b)Miroslav Klose (c)Thomas Muller (d)Pele\n", 'b'),
    Question(
        "Which of the following clubs have not won 'THE TREBLE?''\n"
        "(a)Bayern Munich (b)FC Barcelona (c)Ajax (d)Real Madrid\n", 'd'),
    Question(
        "Which player won Both the Best Player and the Best Goalkeeper in a World Cup Tournamnet?\n"
        "(a)Oliver Kahn (b)Manuel Neuer (c)Iker Casillas (d)David de gea\n",
        'a')
]


def quiz(ques_list):
    print("Quiz round 1! Enter the correct option:\n")
    score = 0
    for question in ques_list:
        # print(question.ques, end="")
        answ = input(question.ques)
        if answ == question.ans:
            score += 1
Example #25
0
from questions import Question

question_prompt = [
    "What Color?\n(a) red/green\n(b) purple\n(c) orange\n\n",
    "What Size?\n(a) red/green\n(b) purple\n(c) orange\n\n",
    "What Weight?\n(a) red/green\n(b) purple\n(c) orange\n\n"
]

questions = [
    Question(question_prompt[0], "a"),
    Question(question_prompt[1], "c"),
    Question(question_prompt[2], "b")
]


def runTest(questions):
    score = 0
    for q in questions:
        answer = input(q.prompt)
        if answer == q.answer:
            score +=1
    print("you got : " + str(score) + "/" + str(len(questions)) + " CORRECT")


runTest(questions)
Example #26
0
##
#  This program shows a simple quiz with one question.
#

from questions import Question

# Create the question and expected answer.
q = Question()
q.setText("Who is the inventor of Python?")
q.setAnswer("Guido van Rossum")      

# Display the question and obtain user's response.
q.display()
response = input("Your answer: ")
print(q.checkAnswer(response))


Example #27
0
from questions import Question
# 创建消息队列
global url_queue
url_queue = Queue()


# 创建任务进程
def create_job(url):
    print url
    Question.get_question(url)


# url_list处理函数
def handle_url_list(url_list):
    pass


if __name__ == '__main__':
    import time
    start = time.time()
    # 获取url参数列表
    url_list = Question.mul_get_url()
    #print url_list
    # 创建线程池
    #pool = threadpool.ThreadPool(10)
    pool = threadpool.ThreadPool(5)
    requests = threadpool.makeRequests(create_job, url_list)
    [pool.putRequest(req) for req in requests]
    pool.wait()
    end = time.time()
    print end - start
##
#  This program shows a simple quiz with one question.
#

from questions import Question
from choicequestion import ChoiceQuestion

# Create the question and expected answer.
q = Question()
q.setText("Who is the inventor of Python?")
q.setAnswer("Guido van Rossum")

# Display the question and obtain user's response.
q.display()
response = input("Your answer: ")
print(q.checkAnswer(response))

cq = ChoiceQuestion()
cq.setText('Test question1')
cq.addText(' new text')
cq.setAnswer('2')
print(cq.checkAnswer('2'))
Example #29
0
def create_job(url):
    print url
    Question.get_question(url)
    cid = 0
    while True:
        url = 'https://mp.weixin.qq.com/mp/homepage?__biz=MzIzMDA1MTM3Mg==&hid=7&sn=eb1bafd2f52396868dd0d37801758f5b&scene=1&devicetype=iOS12.4&version=17000529&lang=zh_CN&nettype=3G+&ascene=7&session_us=gh_fb56fa7dda76&fontScale=100&wx_header=1&cid={}&begin=0&count=100&action=appmsg_list&f=json&r=0.5466809010203566&appmsg_token='.format(
            cid)

        page = requests.post(url)
        assert page.status_code == 200
        pages = page.json()['appmsg_list']

        if len(pages) == 0:
            break

        for p in pages:
            try:
                q_id = int(''.join([ch for ch in p['title'] if ch.isdigit()]))
                q, a = get_content(p['link'])

                content.append(Question(id=q_id, content=q))
                content.append(Answer(id=q_id, content=a))

                print('面试题 {}: Success.'.format(q_id))
            except Exception as e:
                print('面试题 {}: Failed.'.format(p['title']))
                print(p['link'])

        cid += 1

    with open('./data/数据应用学院每日一题.pkl', 'wb') as f:
        pickle.dump(content, f)
Example #31
0
            elif int(choice) == 2:
                Main.cntinue = False

    def database_creation(self):
        """Clean and recreate the database"""
        s.clean_table("alimentsss")
        g.distrib_url()

    def clean_substitued(self):
        """Clean the substituted food database"""
        cntnue = True
        while cntnue:
            z.allquestions[15].play_question()
            choice = input()
            if z.allquestions[15].check_if_choice_is_valable(choice):
                cntnue = False
                if int(choice) == 1:
                    s.clean_table("newaliments")
                else:
                    m.main()


m = Main()
s = Sqlfunc()
g = Generatingdb()
c = Criteria()
q = Question(None, None)
z = Zulu()
m.main()
print("Au revoir")