本文整理汇总了Python中xml.etree.ElementTree.SubElement.attrib['correct']方法的典型用法代码示例。如果您正苦于以下问题:Python SubElement.attrib['correct']方法的具体用法?Python SubElement.attrib['correct']怎么用?Python SubElement.attrib['correct']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.etree.ElementTree.SubElement
的用法示例。
在下文中一共展示了SubElement.attrib['correct']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_MoocMultipleChoiceAssessment_to_xml
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['correct'] [as 别名]
def convert_MoocMultipleChoiceAssessment_to_xml(par):
""" Convert multiple choice question into xml. """
xml = Element('problem')
for key in ['display_name', 'max_attempts']:
xml.attrib[key] = str(par[key])
p = SubElement(xml, 'p')
p.text = par['question']
p = SubElement(xml, 'p')
p.text = 'Please select correct answer'
sub = SubElement(xml, 'multiplechoiceresponse')
sub = SubElement(sub, 'choicegroup')
sub.attrib['label'] = "Please select correct answer"
sub.attrib['type'] = "MultipleChoice"
for i, ans in enumerate(par['answers']):
choice = SubElement(sub, 'choice')
if i == par['correct_answer']:
choice.attrib['correct'] = 'true'
else:
choice.attrib['correct'] = 'false'
choice.text = ans
if 'explanation' in par:
add_solution(xml, par['explanation'])
return xml
示例2: convert_MoocCheckboxesAssessment_to_xml
# 需要导入模块: from xml.etree.ElementTree import SubElement [as 别名]
# 或者: from xml.etree.ElementTree.SubElement import attrib['correct'] [as 别名]
def convert_MoocCheckboxesAssessment_to_xml(par):
"""Convert checkbox assignment into xml. """
xml = Element('problem')
for key in ['display_name', 'max_attempts']:
xml.attrib[key] = str(par[key])
p = SubElement(xml, 'p')
p.text = par['question']
p = SubElement(xml, 'p')
p.text = 'Select the answers that match'
sub = SubElement(xml, 'choiceresponse')
sub = SubElement(sub, 'checkboxgroup')
sub.attrib['label'] = "Select the answers that match"
sub.attrib['direction'] = "vertical"
for i, ans in enumerate(par['answers']):
choice = SubElement(sub, 'choice')
if i in par['correct_answers']:
choice.attrib['correct'] = 'true'
else:
choice.attrib['correct'] = 'false'
choice.text = ans
if 'explanation' in par:
add_solution(xml, par['explanation'])
return xml