fork(1) download
  1. from random import randrange
  2.  
  3. print("Try to guess a number from 1 to 999!")
  4.  
  5.  
  6. def play():
  7. number = randrange(1, 1000)
  8. guess = -1
  9. while guess != number:
  10. guess = int(input("Your guess: "))
  11. if guess < number:
  12. print("Too low.")
  13. elif guess > number:
  14. print("Too high.")
  15. print("You win!")
  16.  
  17. play()
  18. while True:
  19. ans = input("Do you wanna play again? [Y/n] ") + ' '
  20. if ans[0] == 'y':
  21. play()
  22. elif ans[0] == 'n':
  23. print("Have a nice day!")
  24. exit()
Runtime error #stdin #stdout #stderr 0.15s 12264KB
stdin
Standard input is empty
stdout
Try to guess a number from 1 to 999!
Your guess: 
stderr
Traceback (most recent call last):
  File "./prog.py", line 17, in <module>
  File "./prog.py", line 10, in play
EOFError: EOF when reading a line