Mar-19-2019, 09:13 AM
I am having trouble using if statements in python. I'm working on a scrabble-like game for school and I need to make a list of words that are in a dictionary and made up from letters from the users hand. e.g.
Hand: CTHSWA
Word : WATCH
currently the user can enter any combination of letters and the program accepts it.
Code
The hand is a list of max 7 letters.
thanks
Hand: CTHSWA
Word : WATCH
currently the user can enter any combination of letters and the program accepts it.
Code
print(f"Hand: {', '.join(hand)}") user_word = input("Make a word (need help? press H) ").upper() for l in user_word: word_score += scores[l] hand_words = get_words_from_hand(hand, anagrams_of) if user_word == 'H': #Below line should make sure that the hand_words are from acceptable_words which is a list of every word. if any(hand_words) in acceptable_words: print(f"Possible words: {(', '.join(hand_words))}") print(f"Hand: {', '.join(hand)}") user_word = input("Make a word: ").upper() if user_word in acceptable_words: for l in user_word: print("Your word score: "f"{word_score}") word_score += scores[l] print("Your overall score: "f"{word_score}") main(word_score) else: print("thats not a word") main(word_score)
word_scoresis the function that score the users word
hand_wordsare anagrams made of the word
acceptable_wordsis a list that includes every word
The hand is a list of max 7 letters.
thanks