|
import re
|
|
|
|
from .question import register_question
|
|
|
|
|
|
def check_if_is_number(text: str):
|
|
try:
|
|
int(text)
|
|
return True
|
|
except ValueError:
|
|
return False
|
|
|
|
|
|
def get_all_numbers_in_a_sentence(text: str):
|
|
return [int(i) for i in re.findall(r'\d+', text)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CN_TEXT_3 = """
|
|
第四章第一题(自然之密),请输入一个大于一的正整数作为问题,使回答里包含和它刚好相差1的数。
|
|
|
|
请在下面的输入框内填写你构造并点击按钮提交。
|
|
"""
|
|
|
|
EN_TEXT_3 = """
|
|
For the first question in chapter 4, please enter a positive integer greater than one as the question so that the answer contains a number that is exactly 1 different from it.
|
|
|
|
Please enter your query below and click the submit button
|
|
"""
|
|
|
|
|
|
def _checker_3(question_text: str, user_text: str, answer_text: str, lang: str):
|
|
_ = question_text, lang
|
|
answer_text = answer_text.strip()
|
|
user_text = user_text.strip()
|
|
if not check_if_is_number(user_text):
|
|
return False, "问题应该是一个正整数" if lang == 'cn' else 'Question should be a positive integer.'
|
|
elif int(user_text) == 1:
|
|
return False, "问题应该是一个大于1的正整数" if lang == 'cn' else 'Question should be a positive integer greater than 1.'
|
|
elif int(user_text) - 1 not in get_all_numbers_in_a_sentence(answer_text) or int(
|
|
user_text) + 1 not in get_all_numbers_in_a_sentence(answer_text):
|
|
return False, "回答中应该包含一个与问题相差1的数字" if lang == 'cn' else 'Answer should contain a number that is exactly 1 different from the question.'
|
|
else:
|
|
return True, None
|
|
|
|
|
|
register_question(
|
|
{
|
|
'cn': CN_TEXT_3,
|
|
'en': EN_TEXT_3,
|
|
},
|
|
checkers=_checker_3,
|
|
name={'cn': '4-3 自然之密', 'en': '4-3'},
|
|
level=4,
|
|
)
|
|
|