-
Notifications
You must be signed in to change notification settings - Fork 0
/
trials.py
executable file
·186 lines (177 loc) · 10.8 KB
/
trials.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/python
print "content-type:text/html\n"
import random
import cgi
import cgitb
import data
cgitb.enable()
def quiz(question, answer, wrong1, wrong2, wrong3):
"""will accept a question and 4 answer choices in string format, and
will format this into a quiz"""
s = question
s += '<br><form action="trials.py" method="GET"><br>'
"""Organizes the 4 answer choices completely randomly"""
if random.randrange(4) == 0:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
if random.randrange(3) == 0:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
elif random.randrange(3) == 1:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
else:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
elif random.randrange(4) == 1:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
if random.randrange(3) == 0:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
elif random.randrange(3) == 1:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
else:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
elif random.randrange(4) == 2:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
if random.randrange(3) == 0:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
elif random.randrange(3) == 1:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
else:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
else:
s += '<input type="submit" name="' + wrong3 + '" value="' + wrong3 + '">'
if random.randrange(3) == 0:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
else:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
elif random.randrange(3) == 1:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
else:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
else:
s += '<input type="submit" name="' + answer + '" value="' + answer + '">'
if random.randrange(2) == 0:
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
else:
s += '<input type="submit" name="' + wrong1 + '" value="' + wrong1 + '">'
s += '<input type="submit" name="' + wrong2 + '" value="' + wrong2 + '">'
s += userdata
s += '<input type="hidden" name="qnumber" value="' + str(int(qnumber) + 1) + '">'
s += '<input type="hidden" name="questionNumber" value="' + str(questionNumber) + '">'
s += '</form>'
return s
inputs = cgi.FieldStorage()
if 'usr' not in inputs or 'password' not in inputs or 'level' not in inputs:
print '<html><head><title>Nerdit</title><link rel="stylesheet" type="text/css" href="nerdit.css"></head><body><center><a href=index.html>Userdata Not Found</a></center></body></html>'
else:
print data.header
level = inputs['level'].value
if level == '0':
print '<h1>You have been blocked from the site.</h1><br><a href=index.html>Click to go back to Login</a>'
else:
questionNumber = inputs['questionNumber'].value
qnumber = inputs['qnumber'].value
usr = inputs['usr'].value
password = inputs['password'].value
userdata = "<input type='hidden' name='usr' value=" + usr + "><input type='hidden' name='password' value=" + password + "><input type='hidden' name='level' value=" + level + ">"
"""File in format 'question%@answer%@wrong1%@wrong2%@wrong3\nquestion%@..."""
f = open('nerd.txt')
s = f.read()
f.close()
s = s.split('\n')
r = s[int(questionNumber)]
r = r.split('%@')
if (r[2] not in inputs) and (r[3] not in inputs) and (r[4] not in inputs):
print '<br>'
if int(qnumber) < 5:
questionNumber = random.randrange(len(s))
s = s[questionNumber]
s = s.split('%@')
print quiz(s[0], s[1], s[2], s[3], s[4])
elif int(qnumber) >= 5:
lst = data.subsplit('names.txt', '@%')
count = 0
while count < len(lst):
if lst[count][0] == usr:
if lst[count][2] == '5':
print "<h1>You are already on the admin level!</h1>"
elif int(lst[count][2]) < 4:
lst[count][2] = str(int(lst[count][2]) + 1)
level = lst[count][2]
userdata = "<input type='hidden' name='usr' value=" + usr + "><input type='hidden' name='password' value=" + password + "><input type='hidden' name='level' value=" + level + ">"
f = open('names.txt', 'w')
ncount = 0
print 'Your level has been increased to ' + str(int(lst[count][2])) + '!<br>'
while (ncount < len(lst)):
f.write(lst[ncount][0] + '@%' + lst[ncount][1] + '@%' + lst[ncount][2] + '\n')
ncount += 1
elif int(lst[count][2]) == 4:
print "<h1>You are on the highest level. To be increase to the even higher level, you must enter the admin password below!</h1>"
count += 1
else:
print '<h1>You are incorrect!</h1>'
print '<form action="trials.py" method="GET">' + userdata + '<input type="hidden" name="qnumber" value="0"><input type="hidden" name="questionNumber" value="0"><input type="submit" name="quiz" value="Try again"></form>'
print "<br><form action='home.py' method='GET'>" + userdata
print "<input type='submit' class='linkbutton' name='home' value='Click to Return to Homepage'></form>"
print '<br><br><form action="admin.py" type="GET">' + userdata + '<input type="password" name="adminpw" required><input type="submit" name="admin" value="Upgrade to Admin"></form>'
print data.footer