Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using if statements
#1
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
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_scores
is the function that score the users word
hand_words
are anagrams made of the word
acceptable_words
is a list that includes every word

The hand is a list of max 7 letters.

thanks
Reply


Messages In This Thread
Using if statements - by bradystroud - Mar-19-2019, 09:13 AM
RE: Using if statements - by Larz60+ - Mar-19-2019, 03:23 PM
RE: Using if statements - by ichabod801 - Mar-19-2019, 03:40 PM
RE: Using if statements - by bradystroud - Mar-20-2019, 06:56 AM
RE: Using if statements - by ichabod801 - Mar-20-2019, 01:55 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020