Пример #1
0
def get_security_question(username):
    mydb.open()
    result = mydb.query_db('select * from account WHERE username = ? ', [username], one=True)
    mydb.close_db()
    if result:
        questions = question(result['sq_1'],result['as_1'],result['sq_2'],result['as_2'],result['sq_3'],result['as_3'])
        return questions
    else:
        return None
Пример #2
0
def verify(username, password):
    mydb.open()
    result = mydb.query_db('select * from account WHERE username = ? and pwd = ?', [username, password], one=True)
    mydb.close_db()
    if result:
        if not result['sq_1'] == None:
            print result['sq_1']
            questions = question(result['sq_1'],result['as_1'],result['sq_2'],result['as_2'],result['sq_3'],result['as_3'])
        else:
            questions=None
        return User(result['username'], result['type'], result['status'], questions)
    else:
        return None
Пример #3
0
 def set_questions(self, q_name):
     q_list = {}
     with open(os.path.join(os.getcwd(), 'quiz_wise_questions', q_name),
               'r') as file:
         reader = csv.DictReader(file)
         for row in reader:
             q_list[row['ques_no']] = question(row)
             self.unattempted.append(row['ques_no'])
             self.total_quiz_marks += int(row['marks_correct_ans'])
         tstring = reader.fieldnames[-1]
         h_match = re.search(r'\d+(?=h)', tstring)
         m_match = re.search(r'\d+(?=m)', tstring)
         hh, mm = 0, 0
         if h_match:
             hh = int(h_match.group())
         if m_match:
             mm = int(m_match.group())
         self.timer = 60 * (mm + hh * 60)
     return q_list
# In the end it shows the score
# Please refer to "Question.py" to see the class and the method

# Import the question class from Question
from Question import question

# Stor the questions in a list
question_prompt = [
    "What color are apples?\n(a) Red/Green\n(b) Purple\n(c) Orange\n",
    "What color are bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n",
    "What color are cherries?\n(a) Yellow\n(b) Red\n(c) Blue\n",
]

# initialising the list with class question
questions = [
    question(question_prompt[0], "a"),
    question(question_prompt[1], "c"),
    question(question_prompt[2], "b")
]


# Defining a funtion to run the test when called
def run_test(questions):
    score = 0  # Set the score as 0
    for question in questions:  # For every question in the question list
        answer = input(question.prompt + "\nanswer: "
                       )  # Get input from the user for each question as answer
        if answer == question.answer:  # IF user's answer == the stored answer
            score += 1  # Score increments by 1
    print("Ypu get" + str(score) + "/" +
          str(len(questions)))  # At the end of the for loop print the score
Пример #5
0
from Question import question

question_prompt = [
    'What color are apples?\n(a) Red/Green\n(b) Purple\n(c) Orange\n\n',
    'What color are Bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\n',
    'What color are Strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n'
]

questions = [
    question(question_prompt[0], 'a'),
    question(question_prompt[1], 'c'),
    question(question_prompt[2], 'b'),
    question(
        'Who is indian cricket team caption?\n(a) Dhoni\n(b) Gavskar\n(c) Kohli\n(d) Sharma\n\n',
        'd')
]


def test_run(questions):
    score = 0
    for question in questions:
        answer = input(question.prompt)
        if answer == question.answer:
            score += 1
    print('Result : ', score, '/', str(len(questions)))


test_run(questions)
student1 = student("Jim", "Business", 3.1, False)

print(student1.name)

### Multiple Choice Quiz

from Question import question  # Question = Question.py (see below)

question_prompts = [
    "What color are apples?\n(a) Red/Green\n(b) Purple\n(c) Orange\n\n",
    "What color are bananas?\n(a) Teal\n(b) Magenta\n(c) Yellow\n\n",
    "What color are strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n"
]

questions = [
    question(question_prompts[0], "a"),
    question(question_prompts[1], "c"),
    question(question_prompts[2], "b"),
]


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


run_test(questions)