so im doing this http://ift.tt/2xeU7nB and ive gotten stuck with one part. im trying to use nested loops to go through every word in the word list (a text file I have open), and for every letter in that word, see if that letter is contained in the user input. my code so far is import argparse import sys
file=open('sowpods.txt','r')#opens the file of words used in scrabble
scores = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
"f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
"l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
"r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
"x": 8, "z": 10}#dictionary for letter values
parser=argparse.ArgumentParser(description='designed to help in scrabble')
#command line interface using argparse module
parser.add_argument("word",help="input your letters",nargs='?')#adds the
positional argument with description
args=parser.parse_args()
if args.word is None:
print('error I need letters to work')
sys.exit()
else:
print(str.lower(args.word))#converts the the input for argument word
into lowercase letters
for letter in file:
for i in letter:
for i in args.word:
valid=[]
valid.append(i)
print(valid)
the expected output should look like this
python scrabble.py ZZAAEEI
zeze
ziz
basically a list of the valid words.
once I have this list I can get the value of the word using the scores dictionary but im stuck since I thought nested loops would be the best way. thanks for any help.
Aucun commentaire:
Enregistrer un commentaire