fork download
  1. import threading, time
  2. import sys
  3. import random
  4. from queue import Queue
  5.  
  6. MIN, MAX = 0, 100 # number range in which random integer is created
  7. THRESHOLD = 15 # time given to a player
  8.  
  9.  
  10. def countdown(n: int):
  11. '''Countdown function. From n to 0'''
  12. while n > 0:
  13. sys.stderr.write(f'\n{n}')
  14. time.sleep(1)
  15. n -= 1
  16. sys.stderr.write(f'\nOVER')
  17.  
  18.  
  19. def game():
  20. '''Represents the game. Must be executed in daemon'''
  21. num = random.randint(MIN, MAX)
  22. print(f'Game started. Enter your number (from {MIN} to {MAX})')
  23. while True:
  24. guess = int(input('Your guess: '))
  25. if guess > num:
  26. print(f'Wrong! {guess} is GREATER than the target')
  27. elif guess < num:
  28. print(f'Wrong! {guess} is SMALLER than the target')
  29. elif guess == num:
  30. print(f'You are RIGHT! {guess} is the number')
  31. break
  32.  
  33.  
  34. def main():
  35. counter = threading.Thread(target=countdown, args=[THRESHOLD])
  36. daemon_game = threading.Thread(target=game, daemon=True)
  37. counter.start()
  38. daemon_game.start()
  39.  
  40.  
  41. if __name__ == '__main__':
  42. main()
Time limit exceeded #stdin #stdout #stderr 5s 12900KB
stdin
Standard input is empty
stdout
Game started. Enter your number (from 0 to 100)
Your guess: 
stderr
15