-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz_main.py
83 lines (78 loc) · 2.22 KB
/
quiz_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import random
import os
import time
#Importing Login module
import login
def private(): #Private Key Generation for use of the main quiz function.
s=''
letters='qwertyuioplkjhgfdsazxcvbnm'
letters+=letters.upper()
letters+='234567890'
letters+="!@#$%^&*?/'"
for i in range(8):
s+=random.choice(letters)
return 'AB '+s
passcode,correct = 0,private()
_pass=False
def main(quiz_no=1,passpercent=65):
global passcode,correct
passcode=correct
file='quiz '+str(quiz_no)+'.txt'
quiz(file,passpercent)
def quiz(file,passpercent): #Main quiz function.
global _pass
if passcode!=correct:
print("Fake")
time.sleep(2.5)
os._exit(1)
return
marks=0
ob=open(file,'r')
ans=eval(ob.readline())
total_ques=len(ans.keys())
q=ob.readlines()
done=[]
no=0
max_no=int(2*(total_ques/3))
while True:
i=random.randint(1,total_ques)
k=0
for a in done:
if i==a:
k=1
if k==1:
continue
no+=1
if no>max_no:
break
if no<=max_no:
line=(i-1)*5
print('\n',no,'.',q[line][2:],end='',sep='')
for a in range(line+1,line+5):
print(q[a],end='')
user_ans=input("Enter your answer -<a/b/c/d>- -> ")
if user_ans.isdigit():
p=int(user_ans)
if p==1:
user_ans='a'
elif p==2:
user_ans='b'
elif p==3:
user_ans=='c'
elif p==4:
user_ans=='d'
if user_ans.lower()==str(ans[i]):
print('Correct')
marks+=1
print("Marks :",marks)
else:
print('Wrong')
print("Marks :",marks)
done+=[i,]
print("\nTotal marks obtained are : ",marks,"/",max_no)
if marks >=((passpercent/100)*max_no):
_pass = True
ob.close()
if __name__ == '__main__': #Checking whether program called directly or by any other module
if login.admin():
main()