Spaces:
Runtime error
Runtime error
File size: 3,005 Bytes
fe81191 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import random
from typing import Literal
def generate_question_answer_pair(level: Literal["easy", "medium", "hard"] = "easy"):
"""generate question and correct answer to it
:param mode: number we add to current number to get an outcome
:param current_number: current number we are counting up from
:param ordinal_number: the number we count up by"""
numbers = generate_numbers_by_level(level)
current_number = numbers['current_number']
ordinal_number = numbers['ordinal_number']
times = numbers['times']
proper_outcome = current_number + ordinal_number * times
question_data = [
{
"question": f"Let's practice counting. After {current_number}, what number is next?",
"current_number": current_number,
"ordinal_number": ordinal_number,
"answer": current_number + 1
},
{
"question": f"What number comes {ordinal_number} number after {current_number}?",
"current_number": current_number,
"ordinal_number": ordinal_number,
"answer": current_number + ordinal_number
},
{
"question": f"We're counting up by {times}s. What number is {ordinal_number} after {current_number}?",
"current_number": current_number,
"ordinal_number": ordinal_number,
"times": times,
"answer": proper_outcome
},
{
"question": f"If we count up {ordinal_number} from {current_number}, what number is next?",
"current_number": current_number,
"ordinal_number": ordinal_number,
"answer": current_number + ordinal_number
},
{
"question": f"Let's count up by {ordinal_number}s. What number is next if we start from {current_number}",
"current_number": current_number,
"ordinal_number": ordinal_number,
"answer": current_number + ordinal_number
}
]
random_choice = random.choice(question_data)
return random_choice
def generate_numbers_by_level(level: Literal["easy", "medium", "hard"] = "easy"):
"""generate current number, ordinal number and times parameter
returns
dict with params:
:param current_number: current number
:param ordinal numebr: the number we count up by
:param times: the number of times we count up by ordinal number"""
if level == "easy":
current_number = random.randint(1, 8)
ordinal_number = random.randint(1, 2)
times = 1
elif level == "medium":
current_number = random.randint(1, 90)
ordinal_number = random.randint(1, 5)
times = random.randint(1, 2)
elif level == "hard":
current_number = random.randint(1, 425)
ordinal_number = random.randint(1, 25)
times = random.randint(1, 3)
return {
"current_number": current_number,
"ordinal_number": ordinal_number,
"times": times
}
|