1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Scrabble Word Finder and point counter function not computing?

Discussão em 'Python' iniciado por Stack, Setembro 7, 2025.

  1. Stack

    Stack Membro Participativo

    Here is what I'm supposed to do:

    Scrabble Word Finder: Your user will enter the tiles which they currently have. Your program will print all words in the dictionary which can be created by those tiles. Then, it will print the word with the most scrabble points and the point total.

    Here is my code thus far:

    def main():
    scrabblefinder()

    def scrabbleFinder():
    value_list = {'a': 1, 'b': 3, 'c': 3, 'd': 2, 'e': 1, 'f': 4, 'g': 2,
    'h': 4, 'i': 1, 'j': 8, 'k': 5, 'l': 1, 'm': 3, 'n': 1,
    'o': 1, 'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1, 'u': 1,
    'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10}
    string1=str(input("What tiles do you have?: "))
    ls1 = list(string1)
    string2 = open("scrabble_wordlist_finder.txt","r")
    highest = 0
    higheststring = ""
    points = 0
    for line in string2:
    ls2=list(line)
    if len(string1)+1>=len(line):
    #ls2.sort()
    x=0
    for n in ls2:
    if n >= ls1[x+1]:

    x+=1
    else:
    break
    if x+1>=len(ls2):
    line=line.strip();
    word_index = 0
    total = 0
    points = sum(value_list[char] for char in line)
    if points > highest:
    highest = points
    higheststring = line
    print(str(line),",",points,"points")
    print("The highest scoring word is:",higheststring,",",points,"points.")
    main()


    However, if I enter the tiles, for example, "qwertyas", it will print the following:

    we , 5 points
    wert , 7 points
    west , 7 points
    wet , 6 points
    why , 12 points
    wiry , 10 points
    wis , 6 points
    wist , 7 points
    wit , 6 points
    witty , 11 points
    wiz , 15 points
    wo , 5 points
    wort , 7 points
    wos , 6 points
    wost , 7 points
    wot , 6 points
    wow , 9 points
    wry , 9 points
    xi , 9 points
    xis , 10 points
    xu , 9 points
    xyst , 14 points
    ye , 5 points
    yes , 6 points
    yet , 6 points
    yett , 7 points
    yew , 9 points
    you , 6 points
    yow , 9 points
    yurt , 7 points
    zest , 13 points
    zesty , 17 points
    The highest scoring word is: zesty , 17 points.


    Why is it printing tiles that I didn't even enter? Also, why isn't it removing tiles so they can't be used again?

    Continue reading...

Compartilhe esta Página