Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- def is_valid_word(word, starting_word):
- # Check if the word is long enough
- if len(word) < 3:
- return False
- # Check if the word is made up of only letters in the starting word
- letter_counts = collections.Counter(word)
- for letter, count in letter_counts.items():
- if letter not in starting_word or starting_word.count(letter) < count:
- return False
- return True
- def get_word_from_user(n):
- word = input(f"Enter a word with at least {n} characters: ")
- # Convert the word to lowercase to handle case-insensitive input
- return word.lower()
- def play_wordbuilder():
- starting_word = get_word_from_user(6)
- score = 0
- used_words = []
- while True:
- word = get_word_from_user(3)
- if is_valid_word(word, starting_word):
- if word in used_words:
- print("You have already entered this word. Please enter a new word.")
- else:
- used_words.append(word)
- score += 1
- else:
- print("Invalid word. Please try again.")
- print(f"Your current score is {score}.")
- play_wordbuilder()
Advertisement
Add Comment
Please, Sign In to add comment