Example #1
0
def main():
    run = 'y'
##    # Location of the mcqs.txt file
    mcqloc = 'subjects\\python\\mc\\mcqs'
##    # Total number of multiple choice questions
    MCQS = fp.lines_in(mcqloc)
##    # Location of the tfqs.txt file
    tfqloc = 'subjects\\python\\tf\\tfqs'
##    # Total number of T/F questions
    TFQS = fp.lines_in(tfqloc)
##    # Total number of questions constant
    TOTALQS = MCQS + TFQS
    # Questions list, remove num once asked
    mcqs = list(range(1, MCQS + 1))
    tfqs = list(range(1, TFQS + 1))

    while run == 'y':

        ask_q_set(tfqs, mcqs, TFQS, MCQS, tfqloc, mcqloc)

        '''When player is out of questions print the % correct'''
        prnt_score(correct, TOTALQS, tfwrong, mcwrong)
        
        '''Ask to review incorrect questions'''
        review = valid.yes_no('Review the questions answered incorrectly')
        
        '''Ask to run again'''
        run = valid.yes_no('Run Again')
Example #2
0
def addAnswer(sub, qz, qType):
    if qType == 'Tf':
        print('Enter the Answer(T/F)')
        with open('subjects\\' + sub + '\\' + qz + '\\tf\\as\\tfas.txt',
                  'a') as f:
            f.write(valid.in_choices(['True', 'False']) + '\n')
            f.close()
    else:
        qNum = fp.lines_in('subjects\\' + sub + '\\' + qz + '\\' + qType +
                           '\\' + qType.lower() + 'qs')
        f = open(
            'subjects\\' + sub + '\\' + qz + '\\' + qType + '\\as\\' +
            qType.lower() + 'a' + str(qNum) + '.txt', 'w')
        for i in range(4):
            while 1:
                if i == 0:
                    fp.s_txt()
                    ans = input('Enter the CORRECT answer:')
                    fp.s_txt()
                else:
                    fp.s_txt()
                    ans = input('Enter a FALSE answer:')
                    fp.s_txt()
                if valid.yes_no('Is "' + ans +
                                '" the answer you want to add') == 'y':
                    f.write(ans + '\n')
                    break
        f.close()
Example #3
0
def ask_q_set(sub, rev = 'n', xrlist = [], yrlist = []):
    # Questions answeres incorrectly from corresponding lists.
    xwrong = []
    ywrong = []
    # Current question
    currQ = 1
    # Number answered correctly
    c = 0
    # Set location of subject question type folder.
    xloc = 'subjects\\' + sub + '\\mc'
    yloc = 'subjects\\' + sub + '\\tf'
    if os.path.exists(xloc):
    # Set number of questions in each file
        xLines = fp.lines_in(xloc + '\\mcqs')
    if os.path.exists(yloc):
        yLines = fp.lines_in(yloc + '\\tfqs')    

    if rev == 'y':
        '''Use the questions answered incorrectly as the question list'''
        x = xrlist
        y = yrlist
        totQs = len(xrlist) + len(yrlist)
    else:
        # Create lists of range of nums according to qs in file
        x = list(range(1, xLines + 1))
        y = list(range(1, yLines + 1))
        # Add qs to total number of questions
        totQs = xLines + yLines
        
    '''Run until all questions are asked.'''
    while len(x) > 0 or len(y) > 0:
        '''Print Q# out of totQs'''
        fp.s_txt(24)
        print('Question ' + str(currQ), 'out of ' + str(totQs) + ':')
        fp.s_txt(24)
        
        '''Get list to choose q from'''
        qlist = q_list(x, y)
    
        if qlist == 0:
            '''select the nxtq number,'''
            nxtq = q_select(x, xLines)
            '''remove the nxtq number from the respective q list'''
            x.remove(nxtq)
            qloc = xloc + '\\mcqs'
            answers, choices, cans = mc_ans_build(xloc, nxtq)
        else:
            nxtq = q_select(y, yLines)
            y.remove(nxtq)
            qloc = yloc + '\\tfqs'
            answers, choices, cans = tf_ans_build(yloc, nxtq)
##        print('CANS = ' + str(cans))
        '''Ask the question'''
        q_ask(nxtq, qloc)
        '''Print the answers'''
        q_ans_disp(answers)
        '''Get the user's answer'''
        uans = get_usr_ans(choices)
        
        '''Compare answers, if user answer is correct, increment correct'''
        if uans == cans:
            c += 1
        elif qlist == 0:
            xwrong.append(nxtq)
        else:
            ywrong.append(nxtq)
        currQ += 1
    return c, totQs, xwrong, ywrong