def on_launch(self, request: LaunchRequest, session: Session) -> Response: word, definition = get_random_word() return Response( Body(speech=Speech('Definition for word: {} is: {}'.format( word, definition)), card=StandardCard(title=word.capitalize(), body=definition.capitalize())))
def give_me_a_word(request: IntentRequest, session: Session) -> Response: word, definition = get_random_word() return Response( Body(speech=Speech('Definition for word: {} is: {}'.format( word, definition)), card=StandardCard(title=word.capitalize(), body=definition.capitalize())))
def get_phrase(level): """Returns a phrase to type based on the level.""" # Get the number of words that are supposed to be in # the phrase to type, according to the level. num_words_in_phrase = get_num_words_by_level(level) phrase = '' while num_words_in_phrase > 0: # Continue adding words to the phrase until it has # the appropriate number of words. word = dictionary.get_random_word(1) phrase = phrase + ' ' + word num_words_in_phrase = num_words_in_phrase - 1 return phrase.strip()
def new_game(self, request): """Creates new game""" user = User.query(User.name == request.user_name).get() if not user: raise endpoints.NotFoundException( 'A User with that name does not exist!') """Only start a game if none exist or if all have been finished""" games = Game.query(ancestor=user.key) if games is not None: for game in games.iter(): if game.game_status == 'Playing': raise endpoints.BadRequestException( 'A game is already going for the user!') game = Game.new_game(user.key, dictionary.get_random_word()) # Use a task queue to update the average attempts remaining. # This operation is not needed to complete the creation of a new game # so it is performed out of sequence. # taskqueue.add(url='/tasks/cache_average_attempts') return game.to_form('Good luck playing Hangman!')
def __init__(self): self.secret = get_random_word() self.guesses = '' self.max_turns = 15 self.turns_played = 0 self.won = False
import time from dictionary import get_random_word secret = get_random_word() guesses = '' max_turns = 10 turns_played = 0 won = False while max_turns > turns_played and not won: missing = 0 for letter in secret: if letter in guesses: print(letter, end="") else: print("_", end="") missing +=1 print() if not missing: print("Blip Blop ! You may have won the battle, but not the war!") won = True break guess = input("Guess a character: ") #print(guess) guesses += guess if guess not in secret: turns_played +=1