-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_db.py
More file actions
76 lines (65 loc) · 2.49 KB
/
populate_db.py
File metadata and controls
76 lines (65 loc) · 2.49 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
import sqlite3
import json
def insert_question(module, question, type, options, answer):
conn = sqlite3.connect('exercises.db')
c = conn.cursor()
# Convert options to JSON string if necessary
if isinstance(options, list):
options = json.dumps(options)
c.execute('''
INSERT INTO questions (module, question, type, options, answer)
VALUES (?, ?, ?, ?, ?)
''', (module, question, type, options, answer))
conn.commit()
conn.close()
if __name__ == '__main__':
# Insert sample R programming questions in module 'mod-1'
insert_question(
module='mod-1',
question='Which function is used to print output in R?',
type='mcq',
options=[{'option': 'print()'}, {'option': 'echo()'}, {'option': 'display()'}, {'option': 'show()'}],
answer='print()'
)
insert_question(
module='mod-1',
question='What will be the output of `class(42L)` in R?',
type='mcq',
options=[{'option': '"numeric"'}, {'option': '"integer"'}, {'option': '"double"'}, {'option': '"character"'}],
answer='"integer"'
)
insert_question(
module='mod-1',
question='What symbol is used for assignment in R?',
type='mcq',
options=[{'option': '='}, {'option': '->'}, {'option': '<-'}, {'option': ':='}],
answer='<-'
)
insert_question(
module='mod-1',
question='What function in R is used to get the structure of an object?',
type='mcq',
options=[{'option': 'structure()'}, {'option': 'class()'}, {'option': 'typeof()'}, {'option': 'str()'}],
answer='str()'
)
insert_question(
module='mod-1',
question='What is the correct way to create a sequence from 1 to 10 in R?',
type='mcq',
options=[{'option': 'seq(1,10)'}, {'option': '1:10'}, {'option': 'c(1:10)'}, {'option': 'All of the above'}],
answer='All of the above'
)
insert_question(
module='mod-1',
question='How do you check the length of a vector `v` in R?',
type='fill_in_the_blank',
options=None,
answer='length(v)'
)
insert_question(
module='mod-1',
question='What function is used to read a CSV file in R?',
type='mcq',
options=[{'option': 'read.csv()'}, {'option': 'load.csv()'}, {'option': 'csv.read()'}, {'option': 'import.csv()'}],
answer='read.csv()'
)