If a character in myWord is not a key in the provided dictionary then its score value is 0. Write a function that calculates and returns the total point value of myWord given the Python dictionary object letterPoints which consists of letter : pointValue pairs. In the example above if myLetters = "buoni" and myWord = "boon" then canWeMakeIt should return False.ģ) getWordPoints(myWord, letterPoints) - return an int representing the points for myWord. It’s possible that myLetters will contain multiples of the same letters. You do not need to use all letters in myLetters. Hint: Converting myLetters to a list and using its pop() or remove() method may come in handy. Think about the list functions at your disposal and the tools you’ve learned up till now. Try to write an algorithm on paper first before attempting to write the code. Note that according to the rules of the game, each available letter can only be used once in creating a word. If the input is not the correct type then return False. Write a function which answers the question: Can I form the word myWord from the string of letters myLetters? The function should return a boolean True or False. Note that the last character of every line of the file is the invisible “new line” character '\n' and needs to be sliced off.Ģ) canWeMakeIt(myWord, myLetters) - return True or False. Write a function which reads the file filename and returns a list containing all words in the file. scrabbleWords(myLetters) - NO return (just calls other functions)ġ) createWordList(filename) - return a list of strings.outputWordPointPairs(pointWordList, myLetters, toFile) - NO return (just prints a formatted list or writes it to a file).getWordPoints(myWord, letterPoints) - return an integer representing the point value for a word.canWeMakeIt(myWord, myLetters) - return True or False.createWordList(filename) - return a list of strings.Use the starter code we have provided at the end of the lab. Note that you can also open the file in a new tab/window and copy/paste its contents into a new “wordlist.txt” file in your directory. This file must be downloaded (right click and “save as”) and put into your lab05 directory before you begin, so do that now. So, how did our program know which letter combinations were valid words?……We have to specify a file of words, which you can find here: wordlist.txt. The section “Putting it all together” describes what scrabbleWords() method is supposed to do and how to call the helper functions, so if you want to see the big picture, start reading the section “Putting it all together” first. You will first define four helper functions, which you will then use in the main scrabbleWords() method. For example, if I input 'bouni' as my string of letters, this is what I get: In the end, you will input a string of letters and your program will print out (to the screen and to a file) a list of all possible words you can make along with their point values in descending order (neglecting things like triple letter, double word squares, etc. In this lab assignment, you are going to make your own Scrabble word finder function, scrabbleWords(). The words that players create earn points by counting the points for the letters according to the game rules. Scrabble is a word game in which players take turns placing tiles with individual letters onto a game board. When you have the IDLE window up, you are ready for some programming! The terminal command for this is “ idle3
0 Comments
Leave a Reply. |