-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem_magics.py
64 lines (48 loc) · 1.37 KB
/
problem_magics.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
from ..user.problem_cmds import make_problem, make_qti, show_problem
# from ..user.problem_stack import ProbStack
from .. import ProbStack
from IPython.core.magic import register_cell_magic, register_line_magic
@register_cell_magic
def makeproblem(line, cell):
webassign = False
params = line.split()
if "-wa" in params:
webassign = True
params.remove("-wa")
if len(params) > 0:
pname = params[0]
else:
pname = ""
ProbStack.update_user_funcs()
p = make_problem(cell, ProbStack.user_funcs, webassign)
ProbStack.add(p, pname)
@register_line_magic
def makeqti(line):
if "-nosol" in line:
with_solution = False
line = line.replace("-nosol", "")
else:
with_solution = True
params = line.rpartition(',')
if params[1] == '':
pname = params[2]
pnum = 1
else:
pname = params[0]
try:
pnum = int(params[2])
except ValueError:
pnum = 1
ProbStack.update_user_funcs()
p = ProbStack.get(pname)
if p == None:
print("ERROR: No problem with name " + pname + "found")
return
make_qti(p, pnum, solution=with_solution, externals=ProbStack.user_funcs)
@register_line_magic
def showproblem(line):
p = ProbStack.get(line)
if p:
show_problem(p)
else:
print("Problem not found")