Files
edx-platform/lms/lib/loncapa/loncapa_check.py
2012-07-03 17:06:39 -04:00

37 lines
887 B
Python

#!/usr/bin/python
#
# File: mitx/lib/loncapa/loncapa_check.py
#
# Python functions which duplicate the standard comparison functions available to LON-CAPA problems.
# Used in translating LON-CAPA problems to i4x problem specification language.
from __future__ import division
import random
import math
def lc_random(lower,upper,stepsize):
'''
like random.randrange but lower and upper can be non-integer
'''
nstep = int((upper-lower)/(1.0*stepsize))
choices = [lower+x*stepsize for x in range(nstep)]
return random.choice(choices)
def lc_choose(index,*args):
'''
return args[index]
'''
try:
return args[int(index)-1]
except Exception,err:
pass
if len(args):
return args[0]
raise Exception,"loncapa_check.lc_choose error, index=%s, args=%s" % (index,args)
deg2rad = math.pi/180.0
rad2deg = 180.0/math.pi