usr bin env python coding cp866 import sqlite3 conn sqlite3 connect te

  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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#! /usr/bin/env python
# -*- coding: cp866 -*-
import sqlite3
conn = sqlite3.connect('test.db', isolation_level=None)
cur = conn.cursor()
try:
cur.execute('create table courses (cid integer primary key autoincrement, \
name_course text, q_qwetions integer)')
cur.execute('create table qwetions (cid integer, qid integer primary key autoincrement, \
qwetion text, apearence integer, q_answers integer)')
cur.execute('create table answers (cid integer, qid integer, aid integer primary key autoincrement, \
answer text, grade integer)')
except sqlite3.Error, e:
print e
x = 0
while x != 5:
x = int(raw_input("""Выберите пункт меню:
1. Создать базу
2. Редактировать базу
3. Вывести базу на экран
4. Удалить базу
5. Выход\n"""))
if x == 1:
y = 0
while y != 4:
y = int(raw_input("""
1. Создать базу
Выберите пункт подменю:
1 - курс,
2 - вопрос,
3 - ответ
4 - вернутся в главное меню\n"""))
if y == 1:
name_course = raw_input('Введите название курса\n')
q_qwetions = int(raw_input('Введите количество вопросов\n'))
cur.execute('insert into courses values(NULL, "%s", "%d" )' % \
(name_course, q_qwetions))
elif y == 2:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
d = cur.execute('select q_qwetions from courses where cid = %d' %cid).fetchone()[0]
for i in range(d):
qwetion = raw_input('Введите вопрос\n')
apearence = int(raw_input('Введите номер представления вопроса\n'))
q_answers = int(raw_input('Введите количество ответов\n'))
cur.execute('insert into qwetions values("%d", NULL, "%s", "%d", "%d" )' % \
(cid, qwetion, apearence, q_answers))
elif y == 3:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from qwetions where cid = %d' %cid)
for row in cur:
print row
qid = int(raw_input('Выберите номер вопроса для работы\n'))
d = cur.execute('select q_answers from qwetions where qid = %d' %qid).fetchone()[0]
for i in range(d):
answer = raw_input('Введите ответ\n')
grade = int(raw_input('Введите балл за этот ответ\n'))
cur.execute('insert into answers values("%d", "%d", NULL, "%s", "%d")' % \
(cid, qid, answer, grade))
elif x == 2:
y = 0
while y != 4:
y = int(raw_input("""
1. Редактировать базу
Выберите пункт подменю:
1 - курс,
2 - вопрос,
3 - ответ
4 - вернутся в главное меню\n"""))
if y == 1:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from courses where cid = %d' %cid)
print cur.execute('select * from courses where cid = %d' %cid).fetchone()
a = int(raw_input("Какой столбец вы хотите исправить?\n"))
if a == 2:
print cur.execute('select name_course from courses where cid = %d' %cid).fetchone()
b = raw_input("На что хотите заменить?\n")
cur.execute('UPDATE courses SET name_course = "%s" where cid = %d' % (b, cid))
elif a == 3:
print cur.execute('select q_qwetions from courses where cid = %d' %cid).fetchone()
b = int(raw_input("На что хотите заменить?\n"))
cur.execute('UPDATE courses SET q_qwetions = "%d" where cid = %d' % (b, cid))
elif y == 2:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from qwetions where cid = %d' %cid)
for row in cur:
print row
qid = int(raw_input('Выберите номер вопроса\n'))
cur.execute('select * from qwetions where qid = %d' %qid)
print cur.execute('select * from qwetions where qid = %d' %qid).fetchone()
a = int(raw_input("Какой столбец вы хотите исправить?\n"))
if a == 3:
print cur.execute('select qwetion from qwetions where qid = %d' %qid).fetchone()
b = raw_input("На что хотите заменить?\n")
cur.execute('UPDATE qwetions SET qwetion = "%s" where qid = %d' % (b, qid))
elif a == 4:
print cur.execute('select apearence from qwetions where qid = %d' %qid).fetchone()
b = int(raw_input("На что хотите заменить?\n"))
cur.execute('UPDATE qwetions SET apearence = "%d" where qid = %d' % (b, qid))
elif a == 5:
print cur.execute('select q_answers from qwetions where qid = %d' %qid).fetchone()
b = int(raw_input("На что хотите заменить?\n"))
cur.execute('UPDATE qwetions SET q_answers = "%d" where qid = %d' % (b, qid))
elif y == 3:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from qwetions where cid = %d' %cid)
for row in cur:
print row
qid = int(raw_input('Выберите номер вопроса\n'))
cur.execute('select * from answers where qid = %d' %qid)
for row in cur:
print row
aid = int(raw_input('Выберите номер ответа\n'))
cur.execute('select * from answers where aid = %d' %aid)
print cur.execute('select * from answers where qid = %d' %qid).fetchone()
a = int(raw_input("Какой столбец вы хотите исправить?\n"))
if a == 4:
print cur.execute('select answer from answers where aid = %d' %aid).fetchone()
b = raw_input("На что хотите заменить?\n")
cur.execute('UPDATE answers SET answer = "%s" where aid = %d' % (b, aid))
elif a == 5:
print cur.execute('select grade from answers where aid = %d' %aid).fetchone()
b = int(raw_input("На что хотите заменить?\n"))
cur.execute('UPDATE answers SET grade = "%d" where aid = %d' % (b, aid))
elif x == 3:
y = 0
while y != 4:
y = int(raw_input("""
1. Выводить базу на экран
Выберите пункт подменю:
1 - курс,
2 - вопрос,
3 - ответ
4 - вернутся в главное меню\n"""))
if y == 1:
cur.execute('select * from courses')
for row in cur:
print row
elif y == 2:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from qwetions where cid = %d' %cid)
for row in cur:
print row
elif y == 3:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from qwetions where cid = %d' %cid)
for row in cur:
print row
qid = int(raw_input('Выберите номер вопроса\n'))
cur.execute('select * from answers where qid = %d' %qid)
for row in cur:
print row
elif x == 4:
y = 0
while y != 4:
y = int(raw_input("""
1. Удалить базу
Выберите пункт подменю:
1 - курс,
2 - вопрос,
3 - ответ
4 - вернутся в главное меню\n"""))
if y == 1:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('delete from courses where cid = %d' %cid)
cur.execute('delete from qwetions where cid = %d' %cid)
cur.execute('delete from answers where cid = %d' %cid)
elif y == 2:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from qwetions where cid = %d' %cid)
for row in cur:
print row
qid = int(raw_input('Выберите номер вопроса\n'))
cur.execute('delete from qwetions values where qid = %d' %qid)
cur.execute('delete from answers values where qid = %d' %qid)
elif y == 3:
cur.execute('select * from courses')
for row in cur:
print row
cid = int(raw_input('Выберите номер курса\n'))
cur.execute('select * from qwetions where cid = %d' %cid)
for row in cur:
print row
qid = int(raw_input('Выберите номер вопроса для дальнейшей работы\n'))
cur.execute('select * from answers where qid = %d' %qid)
for row in cur:
print row
aid = int(raw_input('Выберите номер ответа для удаления\n'))
cur.execute('delete from answers values where aid = %d' %aid)
cur.close()
conn.close()