Quizz Program using Python

Conduct Quizz Program like MCQ( Multi Choice Question ) using python...

Concept:

First, create three text file one for store quizz questions then, second file for store keys for question in quizz and then finally, third file for store the registered student list.

Input / Output:

enter your register number :101

1. What is answer of this expression, 22 % 3 is?
options: A.7  B.1  C.0  D.5

2. What is the output of this expression, 3*1**3?
options: A.27  B.9  C.3  D.1

3. Which of the following will run without errors ?
options: A.round(45.8)  B.round(6352.898,2,5)  C.round()  D.round(7463.123,2,1)

4. What is the output of “hello”+1+2+3 ?
options: A.hello6  B.hello  C.Error  D.hello123

5. Suppose list1 is [1, 3, 2], What is list1 * 2 ?
options: A.[2, 6, 4]  B.[1, 3, 2, 1, 3]  C.[1, 3, 2, 1, 3, 2]  D.[1, 3,  2, 3, 2, 1]

enter 1 questions answer :
1,c

enter 2 questions answer :
2,c

enter 3 questions answer :
3,a

enter 4 questions answer :
4,b

enter 5 questions answer :
5,c

  ==> Total marks 15 in out of 5 questions

Program:

for python 3...

regnum = input("enter your register number :")

mark = 0

stu_ans = []
key_ans = []

auth = open('student_list.txt')

if regnum in auth.read():
    list1 = open(regnum+'.txt','a')        
    qs = open('QuizQuestions.txt','r')    
    print('\n'+qs.read())    
    qs.close()
           
    key = open('key_answer.txt')
    for line in key.readlines():
        key_ans.append(line.strip('\n'))
    
    for i in range(1,6):
        j = str(i)
        print('\nenter '+str(i)+' questions answer : ')
        getoption = input()
        stu_ans.append(getoption)
    
    mark1 = len(set(key_ans).intersection(set(stu_ans)))
    for i in range(0,mark1):
        mark = mark + 5
        
    list1.write('Register No: '+regnum+'\n')
    
    for i in range(len(stu_ans)):
        temp = stu_ans[i]
        temp = str(temp)
        list1.write(temp+'\n')
        temp_mark = str(mark)
    list1.write('  ==> Total marks '+temp_mark+' in out of 5 questions\n')

    print('\n  ==> Total marks '+temp_mark+' in out of 5 questions')

    flist = open('stud_marks.txt','a')
    flist.write('Register No: '+regnum+'\n')
    flist.write('Total mark is '+temp_mark+'\n')
    flist.write('------------------------------\n')
    flist.close()

    list1.close()

    key.close()

auth.close()



-------------------------------------------------------------------------------------------

Comments

Popular posts from this blog

Swap file using python

PyCon-India 2019

Addition Game using Python