Created
December 16, 2016 23:54
-
-
Save Slickness/f680dcd0db2648a734298388ed7daa11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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