def add_problem_to_course(course, problem_type, extra_meta=None):
 assert (problem_type in PROBLEM_DICT)
 factory_dict = PROBLEM_DICT[problem_type]
 problem_xml = factory_dict['factory'].build_xml(**factory_dict['kwargs'])
 metadata = ({'rerandomize': 'always'} if ('metadata' not in factory_dict) else factory_dict['metadata'])
 if extra_meta:
  metadata = dict(metadata, **extra_meta)
 category_name = 'problem'
 return world.ItemFactory.create(parent_location=section_location(course), category=category_name, display_name=str(problem_type), data=problem_xml, metadata=metadata)

def add_problem_to_course ( course , problem_type , extra_meta = None ) : assert ( problem_type in PROBLEM_DICT ) factory_dict = PROBLEM_DICT [ problem_type ] problem_xml = factory_dict [ 'factory' ] . build_xml ( ** factory_dict [ 'kwargs' ] ) metadata = ( { 'rerandomize' : 'always' } if ( 'metadata' not in factory_dict ) else factory_dict [ 'metadata' ] ) if extra_meta : metadata = dict ( metadata , ** extra_meta ) category_name = 'problem' return world . ItemFactory . create ( parent_location = section_location ( course ) , category = category_name , display_name = str ( problem_type ) , data = problem_xml , metadata = metadata )
add a problem to the course we have created using factories .