Advertisement
binemmanuel

Guess It

Oct 21st, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. # This function gets a random word.
  2. def get_word(list_of_words):
  3.     import random
  4.  
  5.     # Store the number of words we have.
  6.     num_of_words = len(list_of_words)
  7.  
  8.     # Get a random integer.
  9.     i = random.randint(0, num_of_words - 1)
  10.  
  11.     # Return a random word.
  12.     return list_of_words[i]
  13.  
  14. # This function disguies a word.
  15. def dis_word(word):
  16.     # Count the word.
  17.     word_count = len(word)
  18.  
  19.     # Get removable characters.
  20.     removable = word[1:(word_count - 1)]
  21.  
  22.     # Count number of removable characters.
  23.     count_removable_char = len(removable)
  24.  
  25.     # Return the word.
  26.     return word.replace(removable, ("_" * count_removable_char))
  27.  
  28. def start(words):
  29.     i = 0
  30.     score = 0
  31.     end = len(words)
  32.  
  33.     while i < end:
  34.         word = get_word(words)
  35.        
  36.         rand_word = dis_word(word)
  37.  
  38.         end -= 1
  39.  
  40.         u_word = input(f'Guess {rand_word}: ')
  41.  
  42.         if word == u_word:
  43.             score += 2
  44.             print(f'Your Score is {score}')
  45.         else:
  46.             print(f'You failed your score is {score}')
  47.        
  48.  
  49. words = ['car', 'cat', 'jeep', 'food', 'test']
  50.  
  51. start(words)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement