def create_game(user_name, misses_allowed): """Create a game""" user = User.get_by_name(user_name) secret_word = secret_word_generator() current_solution = ''.join(['_' for l in secret_word]) # Check if misses_allowed exists and if so make sure it's a number if misses_allowed: if not misses_allowed.isnumeric(): msg = 'Error, only numbers are allowed in misses_allowed' raise endpoints.BadRequestException(msg) else: misses_allowed = int(misses_allowed) else: misses_allowed = 5 game = Game.create_game(user=user.key, misses_allowed=misses_allowed, secret_word=secret_word, current_solution=current_solution) return game.game_state('A new game of Hangman has been created!')