wiki:SandBox

Version 15 (modified by apoirier, 9 years ago) (diff)

--

class GuessANumber(component.Task):
   def go(self, comp):
       attempt = 1
       number = random.randint(1, 20)

       comp.call(util.Confirm('I choose a number between 1 and 20. Try to guess it'))

       while True:
           x = comp.call(util.Ask('Try #%d: ' % attempt))
           x = int(x)

           if x > number:
               comp.call(util.Confirm('Choose a lower number'))

           if x < number:
               comp.call(util.Confirm('Choose a greater number'))

           if x == number:
               comp.call(util.Confirm('You found the secret number in %d tries.' % attempt))
               break

           attempt += 1

Attachments