-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.py
More file actions
83 lines (73 loc) · 1.93 KB
/
Functions.py
File metadata and controls
83 lines (73 loc) · 1.93 KB
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 pickle
import os
def Load_User_Database():
try:
f=open('User_Database.dat','rb')
obj=pickle.load(f)
f.close()
return obj
except:
obj=dict()
return obj
def Write_User_Database(USER_DATABASE,User):
f=open('User_Database.dat','wb')
USER_DATABASE[User.Username]=User
pickle.dump(USER_DATABASE,f)
f.close()
def Load_Question_Database():
# data=[
# {
# 'id':1,
# 'statement':'Input and print factorial.',
# 'explanation':'0!=1 1!=1 3!=6'
# },
# {
# 'id':2,
# 'statement':'Input and print Odd or Even.',
# 'explanation':'0=Even 1=Odd'
# },
# {
# 'id':3,
# 'statement':'Input and print fibonacci.',
# 'explanation':'1=1 2=1 3=2 4=3 5=5 6=8'
# }
# ]
data=[]
for file in os.listdir('Questions'):
f=open('Questions'+'\\'+file+'\\statement.txt','r')
statement=f.read()
f.close()
d={'id':int(file),'explanation':statement}
data.append(d)
data=sorted(data,key=lambda x: x['id'])
return data
def Prepare_rank_list(data_dict):
l=[]
for i in data_dict:
l.append([data_dict[i].Score,data_dict[i].Username])
l.sort(reverse=True)
data=[]
c=1
for i in l:
if data==[]:
data.append([c,i[0],i[1]])
else:
if data[-1][1]==i[0]:
data.append([c,i[0],i[1]])
else:
c+=1
data.append([c,i[0],i[1]])
return data
def Increase_views():
value=0
try:
f=open('Views_Database.dat','rb')
value=pickle.load(f)
f.close()
except:
pass
value+=1
f=open('Views_Database.dat','wb')
pickle.dump(obj=value,file=f)
f.close()
return value