from docx import Document from docx.shared import Inches def get_Options(MCQS ,no): Options=MCQS.get("questions")[no].get('options') Options.append(MCQS.get("questions")[no].get('answer')) random.shuffle(Options) return Options def get_MCQS_Statement(MCQS,i): text=MCQS.get("questions")[i].get("question_statement") return text def get_sq(sq_result,i): text=sq_result.get('questions')[i].get('Question') return text def get_Paragraph(pararesult): text=pararesult.get('Question') return text def get_Paragraph_Question(pararesult): text=pararesult.get("Paraphrased Questions") return text def GenerateMCQSDocument(MCQS): document = Document() document.add_heading('Quiz', 0) table = document.add_table(rows=1, cols=5) hdr_cells = table.rows[0].cells hdr_cells[0].text = 'Statement' hdr_cells[1].text = 'A' hdr_cells[2].text = 'B' hdr_cells[3].text = 'C' hdr_cells[4].text = 'D' for i in range(0,3,1): state=get_MCQS_Statement(MCQS,i) print(state) MCqs_Options=get_Options(MCQS,i) print(MCqs_Options) row_cells = table.add_row().cells row_cells[0].text = str(state) row_cells[1].text = MCqs_Options[0] row_cells[2].text = MCqs_Options[1] row_cells[3].text = MCqs_Options[2] row_cells[4].text = MCqs_Options[3] document.add_page_break() document.save('Document.docx') def GenerateSQDocument(sq_result): document = Document() document.add_heading('Quiz', 0) table = document.add_table(rows=1, cols=1) hdr_cells = table.rows[0].cells hdr_cells[0].text = 'Questions' for i in range(0,3,1): ques=get_sq(sq_result,i) print(ques) row_cells = table.add_row().cells row_cells[0].text = str(ques) document.add_page_break() document.save('Document1.docx') def GenerateParaphraseDocument(pararesult): document = Document() paragraph=get_Paragraph(pararesult) Question=get_Paragraph_Question(pararesult) document.add_heading('Quiz', 0) document.add_paragraph(paragraph,style='Intense Quote') table = document.add_table(rows=1, cols=1) hdr_cells = table.rows[0].cells hdr_cells[0].text = 'Questions' for i in range(0,3,1): row_cells = table.add_row().cells row_cells[0].text = Question[i] document.add_page_break() document.save('Document2.docx')