示例#1
0
def q_ans_build(q, qtype):
    if qtype == 'mcq':
        ans = fp.get_ctnt('subjects\\python\\mc\\as\\mca' + str(q))
        # mca.txt files begin with the answer to the question(on the first line)
        correct = ans[0]
        '''Remove the correct answer from the list'''
        ans.remove(correct)
        '''Shuffle the answers in the list'''
        random.shuffle(ans)
        '''Remove excess false answers from list until there are 3 left'''
        while len(ans) > 3:
            '''Removes last item in list'''
            ans.pop()
        '''All of the above MCqs place the ans last in the list'''
        if correct == 'All of the above.\n':
            ans.append(correct)
            cans = 3
        else:
            '''Normal MCqs randomly insert the correct ans in any spot'''
            cans = random.randint(0, 3)
            ans.insert(cans, correct)
    else:
        ans = fp.get_ctnt('subjects\\python\\tf\\as\\tfcs')
        # T/F ans file retrieved here. r .read()s file
        tfqans = fp.get_ctnt('subjects\\python\\tf\\as\\tfas')
        # T/F correct ans chosen by q index here
        q -= 1
        if tfqans[q] == 'True\n':
            cans = 0
        else:
            cans = 1
    return ans, cans
示例#2
0
def tf_ans_build(yloc, q):
    yansloc = yloc + '\\as\\tf'
    choices = ('A', 'B')
    # T/F print answers
    ans = fp.get_ctnt(yansloc + 'cs')
    # T/F ans file retrieved here. r .read()s file
    tfqans = fp.get_ctnt(yansloc + 'as')
    # T/F correct ans chosen by q index here
    q -= 1
    if tfqans[q] == 'True\n':
        cans = 0
    else:
        cans = 1
    return ans, choices, cans
示例#3
0
def tf_ans_build(yloc, q):
    yansloc = yloc + '\\as\\tf'
    choices = ('A', 'B')
    # T/F print answers
    ans = fp.get_ctnt(yansloc + 'cs')
    # T/F ans file retrieved here. r .read()s file
    tfqans = fp.get_ctnt(yansloc + 'as')
    # T/F correct ans chosen by q index here
    q -= 1
    # I DO NOT like how I have to compare this.
    # I could not find a way to remove the \n.
    if tfqans[q] == 'True\n':
        cans = 0
    else:
        cans = 1
    return ans, choices, cans
示例#4
0
def mc_ans_build(xloc, q):
    xansloc = xloc + '\\as\\mca'
    ans = fp.get_ctnt(xansloc + str(q))
    choices = ('A', 'B', 'C', 'D')
    # mca.txt files begin with the answer to the question(on the first line)
    c = ans[0]
    random.shuffle(ans)
    '''All of the above MCqs place the ans last in the list'''
    if c == 'All of the above.\n':
        ans.append(c)
        cans = 3
    else:
        for i in range(len(ans)):
            if ans[i] == c:
                cans = i
    return ans, choices, cans
示例#5
0
def mc_ans_build(xloc, q):
    xansloc = xloc + '\\as\\mca'
    ans = fp.get_ctnt(xansloc + str(q))
    choices = ('A', 'B', 'C', 'D')
    # mca.txt files begin with the answer to the question(on the first line)
    c = ans[0]
    '''Remove the correct answer from the list'''
    ans.remove(c)
    '''Shuffle the answers in the list'''
    random.shuffle(ans)
    '''Remove excess false answers from list until there are 3 left'''
    while len(ans) > 3:
        '''Removes last item in list'''
        ans.pop()
    '''All of the above MCqs place the ans last in the list'''
    if c == 'All of the above.\n':
        ans.append(c)
        cans = 3
    else:
        '''Normal MCqs randomly insert the correct ans in any spot'''
        cans = random.randint(0, 3)
        ans.insert(cans, c)
    return ans, choices, cans