From 8a105cc3958b9be8581e1ef484592a6b2d2ce684 Mon Sep 17 00:00:00 2001 From: Sailesh Polavarapu Date: Tue, 11 Jan 2022 21:03:53 -0500 Subject: [PATCH] added let m&n>= question --- .../comp2804/let_m_and_n/__init__.py | 0 .../generators/comp2804/let_m_and_n/main.py | 71 +++++++++++++++++++ dynamic/router.py | 10 ++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 dynamic/generators/comp2804/let_m_and_n/__init__.py create mode 100644 dynamic/generators/comp2804/let_m_and_n/main.py diff --git a/dynamic/generators/comp2804/let_m_and_n/__init__.py b/dynamic/generators/comp2804/let_m_and_n/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/dynamic/generators/comp2804/let_m_and_n/main.py b/dynamic/generators/comp2804/let_m_and_n/main.py new file mode 100644 index 00000000..5b1e5d94 --- /dev/null +++ b/dynamic/generators/comp2804/let_m_and_n/main.py @@ -0,0 +1,71 @@ +import random + + +def generate_question(): + # generate required data + k = random.randint(2, 4) # value of k, m and n + + # generate required content + + question_body = ( + "Let $m \geq " + + str(k) + + "$ and $n \geq " + + str(k) + + "$ be integers. What does $${{m}\choose{" + + str(k) + + "}} + {{n}\choose{" + + str(k) + + "}} + m\cdot n$$ count?" + ) + + answer_options = [ + "The number of ways to choose a subset from a set consisting of $m + n$ elements.", + "The number of ways to choose an ordered pair of {} elements from a set consisting of $m + n$ elements.".format( + k + ), + "The number of ways to choose a {}-element subset from a set consisting of $m + n$ elements.".format( + k + ), + "None of the above.", + ] + for answer in answer_options: + if "-element" in answer: + correct_answer = answer + + # return generated question + return { + "title": "set_theory_question", + "body": question_body, + "bodyFormat": "text", + "pseudocode": "", + "multipleChoiceAnswers": [ + { + "body": answer_options[0], + "bodyFormat": "mathjax", + "correct": "true", + }, + { + "body": answer_options[1], + "bodyFormat": "mathjax", + "correct": "false", + }, + { + "body": correct_answer, + "bodyFormat": "mathjax", + "correct": "false", + }, + { + "body": answer_options[3], + "bodyFormat": "mathjax", + "correct": "false", + }, + ], + } + + +def call(): + return generate_question() + + +print(call()) diff --git a/dynamic/router.py b/dynamic/router.py index 325b36ea..4abbe69d 100644 --- a/dynamic/router.py +++ b/dynamic/router.py @@ -9,6 +9,8 @@ import generators.comp2804.set_theory_question.main as set_theory_question_generator import generators.comp2804.num_of_functions.main as num_of_functions_generator import generators.comp2804.bitstrings_of_length.main as bitstrings_of_length_generator +import generators.comp2804.let_m_and_n.main as m_and_n_generator + router = APIRouter( prefix="/api", tags=["generate"], responses={404: {"description": "Not found"}} @@ -26,6 +28,7 @@ "bitstrings-of-length": "/comp2804/bitstrings-of-length", "set-theory-question": "/comp2804/set-theory", "num-of-functions": "/comp2804/num-of-functions", + "let-m-and-n-question": "/comp2804/let-m-and-n", }, } @@ -77,5 +80,10 @@ async def generate_num_of_functions_question( @router.get(routes["comp2804"]["bitstrings-of-length"]) -async def bitstrings_of_length_question(): +async def generate_bitstrings_of_length_question(): return bitstrings_of_length_generator.call() + + +@router.get(routes["comp2804"]["let-m-and-n-question"]) +async def generate_m_and_n_question(): + return m_and_n_generator.call()