import random, time, logging fmt = "%(levelname)s @ ln %(lineno)d in `%(filename)s`: %(message)s" logging.basicConfig(format=fmt, level=logging.DEBUG) logging.warning("DISCLAIMER! This is the legacy version of 'A Game To Play When You're Bored'\nBugs in this version will not be patched and datastores will not be added.") print("This is a game where you guess a number. It's so original!") def main(): try: playTo = int(input("[SETUP] Please enter the amount of guesses you can have (I'd recommend 20)\n> ")) except ValueError: logging.error("Value must be an integer!\n\n") main() except KeyboardInterrupt: logging.debug(f"Exiting via KeyboardInterrupt.") exit() except: logging.fatal("An unhandled exception occured.") exit() print(f'\nGuess a number between 1 and 1000, you will be told if your guess was too low or too high.\nYou have {playTo} guesses.') finalVal = random.randrange(1,1000) guessLeft = playTo for i in range(playTo): try: userNum = int(input("\n> ")) except ValueError: logging.error("Value must be an integer!\nWasting a turn by setting the value to -1...\n\n") userNum = -1 except KeyboardInterrupt: logging.debug(f"Exiting via KeyboardInterrupt, the number was {finalVal}") time.sleep(5) exit() except: logging.fatal("An unhandled exception occured.") exit() if userNum == finalVal: print(f'-=+ YOU WIN! +=-\nWith {guessLeft} guesses remaining.') time.sleep(5) logging.debug("Exiting...") exit() elif userNum < finalVal: print("Too low") guessLeft = guessLeft - 1 print(f'{guessLeft} guesses remaining...') else: print("Too high") guessLeft = guessLeft - 1 print(f'{guessLeft} guesses remaining...') print("\n-=+ GAME OVER +=-") print(f'The number was {finalVal}.') time.sleep(5) logging.debug("Exiting...") exit() if __name__ == "__main__": main()