math_captcha.py
· 401 B · Python
Raw
from random import randint
from random import choice
def capcha() -> ('question', 'answer'):
op = choice(["+", "-", "*", "/"])
if op != "/":
b, a = sorted(randint(0, 25), randint(0, 25))
q = f"{a} {op} {b}"
return q, eval(q)
b, c = randint(0, 5), randint(0, 5)
return f"{b * c} {op} {b}", c
if __name__ == '__main__':
print(' = '.join(map(str, capcha())))
| 1 | from random import randint |
| 2 | from random import choice |
| 3 | |
| 4 | def 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 | |
| 13 | if __name__ == '__main__': |
| 14 | print(' = '.join(map(str, capcha()))) |