Last active 1 month ago

math_captcha.py Raw
1from random import randint
2from random import choice
3
4def capcha() -> ('question', 'answer'):
5 op = choice(["+", "-", "*", "/"])
6 if op != "/":
7 b, a = sorted(randint(0, 25), randint(0, 25))
8 q = f"{a} {op} {b}"
9 return q, eval(q)
10 b, c = randint(0, 5), randint(0, 5)
11 return f"{b * c} {op} {b}", c
12
13if __name__ == '__main__':
14 print(' = '.join(map(str, capcha())))