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
a5b9372e
Commit
a5b9372e
authored
Feb 14, 2012
by
David Ormsbee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
document inability to run evaluator with non-float variables
parent
ed9f2f42
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
courseware/capa/calc.py
+13
-2
No files found.
courseware/capa/calc.py
View file @
a5b9372e
import
copy
import
logging
import
math
import
operator
...
...
@@ -26,11 +27,19 @@ default_variables = {'j':numpy.complex(0,1),
'e'
:
numpy
.
complex
(
numpy
.
e
)
}
log
=
logging
.
getLogger
(
"mitx.courseware.capa"
)
def
evaluator
(
variables
,
functions
,
string
):
''' Evaluate an expression. Variables are passed as a dictionary
from string to value. Unary functions are passed as a dictionary
from string to function '''
from string to function. Variables must be floats.
TODO: Fix it so we can pass integers and complex numbers in variables dict
'''
# log.debug("variables: {0}".format(variables))
# log.debug("functions: {0}".format(functions))
# log.debug("string: {0}".format(string))
all_variables
=
copy
.
copy
(
default_variables
)
all_variables
.
update
(
variables
)
all_functions
=
copy
.
copy
(
default_functions
)
...
...
@@ -150,7 +159,9 @@ if __name__=='__main__':
print
"X"
,
evaluator
(
variables
,
functions
,
"10000||sin(7+5)-6k"
)
print
"X"
,
evaluator
(
variables
,
functions
,
"13"
)
print
evaluator
({
'R1'
:
2.0
,
'R3'
:
4.0
},
{},
"13"
)
#
print
evaluator
({
'e1'
:
1
,
'e2'
:
1.0
,
'R3'
:
7
,
'V0'
:
5
,
'R5'
:
15
,
'I1'
:
1
,
'R4'
:
6
},
{},
"e2"
)
print
evaluator
({
'a'
:
2.2997471478310274
,
'k'
:
9
,
'm'
:
8
,
'x'
:
0.66009498411213041
},
{},
"5"
)
print
evaluator
({},{},
"-1"
)
print
evaluator
({},{},
"-(7+5)"
)
...
...
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