The following post on /r/learnpython prompted me to write this code
https://www.reddit.com/r/learnpython/comments/a4ue6j/python_guessing_game_homework_help/
The current version has some refactoring done, but it is not ideal code yet.
Also, I do not know how to add tests for this.