def generate_mcq_html(question, options, correct_option): html = f'
\n

{question}

\n' for idx, option in enumerate(options): radio_id = f'q{question_num}_correct' if idx == correct_option else f'q{question_num}_{idx}' html += f'
\n' html += f'' html += f' {chr(97 + idx)}) {option}\n' html += '
\n' html += '
\n
' return html # List of MCQ questions, options, and correct answers mcq_list = [ ("What year did Christopher Columbus discover America?", ["1492", "1776", "1812", "1620"], 0), ("The French Revolution began in which year?", ["1789", "1776", "1812", "1492"], 0), ("Who was the first President of the United States?", ["Benjamin Franklin", "Thomas Jefferson", "George Washington", "John Adams"], 2) ] html_output = "" for question_num, (question, options, correct_option) in enumerate(mcq_list, start=1): html_output += generate_mcq_html(question, options, correct_option) print(html_output)

Comments