Queer European MD passionate about IT

game.py 621 B

12345678910111213141516171819202122232425262728
  1. import random
  2. def main():
  3. n = -1
  4. while n < 1:
  5. try:
  6. n = int(input("Level: "))
  7. except (TypeError, ValueError):
  8. continue
  9. random.seed()
  10. n_to_guess = random.randint(1, n)
  11. guess = -1
  12. while n_to_guess - guess != 0:
  13. try:
  14. guess = int(input("Guess: "))
  15. except (TypeError, ValueError):
  16. continue
  17. if guess == n_to_guess:
  18. print("Just right!")
  19. if guess < n_to_guess:
  20. print("Too small!")
  21. if guess > n_to_guess:
  22. print("Too large!")
  23. if __name__ == "__main__":
  24. main()