Skip to content

Instantly share code, notes, and snippets.

@Slickness
Created December 16, 2016 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Slickness/f680dcd0db2648a734298388ed7daa11 to your computer and use it in GitHub Desktop.
Save Slickness/f680dcd0db2648a734298388ed7daa11 to your computer and use it in GitHub Desktop.
#!usr/bin/python3
def main():
option = ""
while option != "q":
option = input("\nwould you like to: \n" \
"\t(c)heck word \n" \
"\t(l)ongest word \n" \
"\t(q)uit\n"\
"Enter your option: ")
if option == "c":
isValid = scrabble()
if isValid:
print ("your word can be made\n")
else:
print ("your word cannot be made\n")
elif option == "l":
longestWord = longest()
print (longestWord)
def longest():
letters = input("Enter your letters: ").lower().strip() # make all lowercase
with open("words.txt","r") as f:
words = f.readlines()
words = sorted(words,key=len)
for word in reversed(words):
word = word.lower().strip()
if len(word) <= len(letters):
isValid = scrabble(word ,letters)
if isValid:
return (word)
def scrabble(word = " ",letters= " "):
# allow users to input valuese or put then n direct
if letters == " ":
letters = input("Enter your letters: ").lower().strip() # make all lowercase
if word == " ":
word = input("Enter your word: ").lower().strip() # make all lowercase
for letter in word:
if letter in letters:
letters = letters.replace(letter,"",1)
#print (letters)
elif "?" in letters:
letters = letters.replace("?","",1)
else:
return False
return True
if __name__=="__main__":
main()
# get variables
#letters = "ladilmy" #place holder for the letters, add input later
#word = "daily" # place holder for word, add input later
#isValid = scrabble(letters, word)
#print(isValid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment