Commit 8b6212cb authored by Michal Čihař's avatar Michal Čihař

Better approach for non negative numbers

parent c0fb82d0
......@@ -42,15 +42,17 @@ class MathCaptcha(object):
'''
Generates random question.
'''
operator = choice(self.operators)
first = randint(self.interval[0], self.interval[1])
second = randint(self.interval[0], self.interval[1])
# We don't want negative answers
if second > first:
first, second = second, first
if operator == '-':
first += self.interval[1]
return '%d %s %d' % (
first,
choice(self.operators),
operator,
second
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment