当前位置: 首页>>代码示例>>Python>>正文


Python SubElement.attrib['correct']方法代码示例

本文整理汇总了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
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:32,代码来源:converter.py

示例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
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:32,代码来源:converter.py


注:本文中的xml.etree.ElementTree.SubElement.attrib['correct']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。