Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This function gets a random word.
- def get_word(list_of_words):
- import random
- # Store the number of words we have.
- num_of_words = len(list_of_words)
- # Get a random integer.
- i = random.randint(0, num_of_words - 1)
- # Return a random word.
- return list_of_words[i]
- # This function disguies a word.
- def dis_word(word):
- # Count the word.
- word_count = len(word)
- # Get removable characters.
- removable = word[1:(word_count - 1)]
- # Count number of removable characters.
- count_removable_char = len(removable)
- # Return the word.
- return word.replace(removable, ("_" * count_removable_char))
- def start(words):
- i = 0
- score = 0
- end = len(words)
- while i < end:
- word = get_word(words)
- rand_word = dis_word(word)
- end -= 1
- u_word = input(f'Guess {rand_word}: ')
- if word == u_word:
- score += 2
- print(f'Your Score is {score}')
- else:
- print(f'You failed your score is {score}')
- words = ['car', 'cat', 'jeep', 'food', 'test']
- start(words)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement