top of page

HANGMAN CODE- DAY 2

  • Writer: MHK
    MHK
  • May 3, 2020
  • 1 min read

Updated: May 8, 2020

DATE: May 3/ 2020



Sorry for the 1 day delay. a

Today I am going to post a function which was the first function that was asked to be implemented on the Hangman Assignment. (I mentioned this assignment in our latest post where you can find the links for this assignment and more, Hangman Introduction.)

Today, the function I am going to write as a code is named is_word_guessed.


This function takes two parameters, secret_word and letters_guessed which are both strings.



For this code, I had help from the internet so this code does not belong to me fully.

SOURCE: https://thispointer.com/python-check-if-a-list-contains-all-the-elements-of-another-lis


def is_word_guessed(secret_word, letters_guessed):      
    '''
    secret_word: string, the word the user is guessing; assumes all letters are lowercase
    letters_guessed: list (of letters), which letters have been guessed so far;
    assumes that all letters are lowercase
    returns: boolean, True if all the letters of secret_word are in letters_guessed;
    False otherwise
      ''' 
      #(This part makes the letters in secret_word and letters_guessed lowercase.)
      letters_guessed=str.lower(letters_guessed)
      secret_word=str.lower(secret_word)
      #(This part checks if all the letters of secret_word are in letters_guessed and returns a boolean.)
      result=all(elem in letters_guessed for elem in secret_word)
      if result:
          return('TRUE')
      else:
          return('FALSE')

COVER IMAGE ADRESS :

( however I wrote the 2 myself.)




Comments


Created By Root Team 

  • Facebook
  • Twitter
  • YouTube
  • Pinterest
  • Tumblr Social Icon
  • Instagram
bottom of page