Advertisement
mayankjoin3

moodle mcq xml

Apr 11th, 2025 (edited)
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.36 KB | None | 0 0
  1. ans = {
  2. 'Q01': 'C',
  3. 'Q02': 'B',
  4. 'Q03': 'A',
  5. 'Q04': 'A',
  6. 'Q05': 'B',
  7. 'Q06': 'A',
  8. 'Q07': 'A',
  9. 'Q08': 'A',
  10. 'Q09': 'C',
  11. 'Q10': 'A',
  12. 'Q11': 'B',
  13. 'Q12': 'A',
  14. 'Q13': 'A',
  15. 'Q14': 'D',
  16. 'Q15': 'A',
  17. 'Q16': 'B',
  18. 'Q17': 'C',
  19. 'Q18': 'A',
  20. 'Q19': 'C',
  21. 'Q20': 'A',
  22. 'Q21': 'B',
  23. 'Q22': 'B',
  24. 'Q23': 'A',
  25. 'Q24': 'B',
  26. 'Q25': 'C'
  27. }
  28.  
  29. start = 53279
  30.  
  31. options = ['A', 'B', 'C', 'D']
  32.  
  33. with open("questions_ENDSEM_JAN_APR25.xml", "w", encoding="utf-8") as f:
  34.     for i in range(1, 26):
  35.         qid = f"Q{i:02}"
  36.         correct = ans.get(qid, None)  # None if not specified
  37.         question_block = f"""<!-- question: {start}  -->
  38.     <question type="multichoice">
  39.         <name>
  40.         <text>{qid}</text>
  41.         </name>
  42.         <questiontext format="html">
  43.         <text><![CDATA[<p> </p>]]></text>
  44.         </questiontext>
  45.         <generalfeedback format="html">
  46.         <text></text>
  47.         </generalfeedback>
  48.         <defaultgrade>1.0000000</defaultgrade>
  49.         <penalty>0</penalty>
  50.         <hidden>0</hidden>
  51.         <idnumber></idnumber>
  52.         <single>true</single>
  53.         <shuffleanswers>false</shuffleanswers>
  54.         <answernumbering>abc</answernumbering>
  55.         <showstandardinstruction>0</showstandardinstruction>
  56.         <correctfeedback format="html">
  57.         <text></text>
  58.         </correctfeedback>
  59.         <partiallycorrectfeedback format="html">
  60.         <text></text>
  61.         </partiallycorrectfeedback>
  62.         <incorrectfeedback format="html">
  63.         <text></text>
  64.         </incorrectfeedback>"""
  65.  
  66.         for opt in options:
  67.             fraction = "100" if correct == opt else "0"
  68.             question_block += f"""
  69.         <answer fraction="{fraction}" format="html">
  70.         <text><![CDATA[<p>Option {opt}</p>]]></text>
  71.         <feedback format="html">
  72.             <text></text>
  73.         </feedback>
  74.         </answer>"""
  75.  
  76.         question_block += """
  77.     </question>\n"""
  78.         f.write(question_block)
  79.         start += 1
  80.  
  81. print("XML file 'questions.xml' generated successfully.")
  82.  
  83.  
  84.  
  85. #preview link is without the option marked.
  86.  
  87. #Mcq testing
  88. #start=53304
  89. #for i in range(25):
  90. #    print(f"""https://cetpgex.iitp.ac.in/moodle/question/bank/previewquestion/preview.php?id={start}&restartversion=0&courseid=314&returnurl=%2Fquestion%2Fedit.php%3Fcourseid%3D314%26cat%3D4836%252C36016%26deleteall%3D1""")
  91.  
  92.    
  93. #    start+=1
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement