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): ...@@ -42,15 +42,17 @@ class MathCaptcha(object):
''' '''
Generates random question. Generates random question.
''' '''
operator = choice(self.operators)
first = randint(self.interval[0], self.interval[1]) first = randint(self.interval[0], self.interval[1])
second = randint(self.interval[0], self.interval[1]) second = randint(self.interval[0], self.interval[1])
# We don't want negative answers # We don't want negative answers
if second > first: if operator == '-':
first, second = second, first first += self.interval[1]
return '%d %s %d' % ( return '%d %s %d' % (
first, first,
choice(self.operators), operator,
second 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