Example #1
0
    def ask_questions(self, team, total_questions, level):
        total_correct = 0
        questions_filename = 'Math_' + str(level) + '.txt'
        # This opens up the file with our questions
        with open(questions_filename) as questionsFile:
            reader = csv.reader(questionsFile, delimiter="\t")
            lines = list(reader)
            tqs = []
            for line in lines:
                if len(line) != 5:
                    continue
                tqs.append(test_question.TestQuestion(line))
        question_dialog = QuestionDialog()
        random.shuffle(tqs)
        for x in range(total_questions):
            question_dialog.ask_question(tqs[x])
            question_dialog.exec_()
            total_correct += question_dialog.result
        print("Your " + team + " team score: " + str(total_correct))
        with open('scores.txt') as scoresFile:
            reader = csv.reader(scoresFile, delimiter="\t", quotechar='^')
            lines = list(reader)

        # python 3 - with open('scores.txt', 'w', newline='') as csvfile:
        with open('scores.txt', 'w') as csvfile:
            writer = csv.writer(csvfile, delimiter='\t',
                                quotechar='^', quoting=csv.QUOTE_MINIMAL)
            for line in lines:
                writer.writerow(line)
            writer.writerow([team, total_correct, total_questions])
        return total_correct
Example #2
0
    def openQuestion(self, btn):
        rcv = self.socketGUI.send("q_" + btn.objectName())  # ex. cat1.100

        dialog = QuestionDialog(rcv)
        ret_status = dialog.exec_()

        if ret_status == QtWidgets.QDialog.Accepted:
            print("Answered = ", dialog.getAnswer())
            #check answer
            answ = json.dumps({
                "question": "cat1.100",
                "answer": dialog.getAnswer()
            })
            print("Data back to server", answ)
            print(type(answ))
            rcv = self.socketGUI.send(answ)
            print("Received back (is correct): ", rcv.get("a"))
            btn.setEnabled(False)