Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
59dfb2cf
Commit
59dfb2cf
authored
Mar 28, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complex numbers now work in problems
parent
c61c6425
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
5 deletions
+10
-5
djangoapps/courseware/capa/responsetypes.py
+10
-5
No files found.
djangoapps/courseware/capa/responsetypes.py
View file @
59dfb2cf
...
...
@@ -37,7 +37,7 @@ class numericalresponse(object):
def
__init__
(
self
,
xml
,
context
):
self
.
xml
=
xml
self
.
correct_answer
=
contextualize_text
(
xml
.
get
(
'answer'
),
context
)
self
.
correct_answer
=
float
(
self
.
correct_answer
)
self
.
correct_answer
=
complex
(
self
.
correct_answer
)
self
.
tolerance_xml
=
xml
.
xpath
(
'//*[@id=$id]//responseparam[@type="tolerance"]/@default'
,
id
=
xml
.
get
(
'id'
))[
0
]
self
.
tolerance
=
contextualize_text
(
self
.
tolerance_xml
,
context
)
...
...
@@ -49,7 +49,10 @@ class numericalresponse(object):
student_answer
=
student_answers
[
self
.
answer_id
]
try
:
correct
=
compare_with_tolerance
(
evaluator
(
dict
(),
dict
(),
student_answer
),
self
.
correct_answer
,
self
.
tolerance
)
except
:
# We should catch this explicitly.
# I think this is just pyparsing.ParseException, calc.UndefinedVariable:
# But we'd need to confirm
except
:
raise
StudentInputError
(
'Invalid input -- please use a number only'
)
if
correct
:
...
...
@@ -141,7 +144,7 @@ class formularesponse(object):
except
:
#traceback.print_exc()
raise
StudentInputError
(
"Error in formula"
)
if
math
.
isnan
(
student_result
)
or
math
.
isinf
(
student_result
):
if
numpy
.
isnan
(
student_result
)
or
numpy
.
isinf
(
student_result
):
return
{
self
.
answer_id
:
"incorrect"
}
if
not
compare_with_tolerance
(
student_result
,
instructor_result
,
self
.
tolerance
):
return
{
self
.
answer_id
:
"incorrect"
}
...
...
@@ -153,9 +156,11 @@ class formularesponse(object):
keys and all non-numeric values stripped out. All values also
converted to float. Used so we can safely use Python contexts.
'''
d
=
dict
([(
k
,
float
(
d
[
k
]))
for
k
in
d
if
type
(
k
)
==
str
and
\
d
=
dict
([(
k
,
numpy
.
complex
(
d
[
k
]))
for
k
in
d
if
type
(
k
)
==
str
and
\
k
.
isalnum
()
and
\
(
type
(
d
[
k
])
==
float
or
type
(
d
[
k
])
==
int
)
])
(
type
(
d
[
k
])
==
float
or
\
type
(
d
[
k
])
==
int
or
\
type
(
d
[
k
])
==
complex
)
])
return
d
def
get_answers
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment