Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program, stored in a file named highest scoring words.py, that performs the following task. Prompts the user to input between 3 and
Write a program, stored in a file named highest scoring words.py, that performs the following task. Prompts the user to input between 3 and 10 lowercase letters (with possibly whitespace inserted any- where); if the input contains too few or too many lowercase letters or any character which is neither a lowercase letter nor whitespace, then the program outputs an error message and exits. Finds in the file dictionary.txt, assumed to be stored in the working directory, the words built from the letters input by the user (with the exclusion of any other character) with highest score, if any; the score of a word is defined as the sum of the values of the letters that make up that word, the value of each letter being defined as follows: a g m 2 b 5 5h 5 i 5 n 2 0 s 1 t 2 y 5 z 7 f6 4 d 4 e 1 1 j 7 k 6 3p 5 q 7 3 r 2 11 4 V 6 W 6 X 7 Outputs a specific message if there is no such word; otherwise, outputs the highest score and all words with that score, one word per line, with a different introductory message depending on whether there is a unique such word (in which case the introductory message is on the same line as the word) or at least two such words (in which case the introductory message is on a line of its own and all words are preceded with 4 spaces). Here is a possible interaction. $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: abc2ef Incorrect input, giving up... $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: ab Incorrect input, giving up... $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: abcdefghijk Incorrect input, giving up... $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: zz zz zz No word is built from some of those letters. $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: a a a The highest score is 2. The highest scoring word is a $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: a e 1 ou The highest score is 8. The highest scoring words are, in alphabetical order: 10u oui $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: pragroa The highest score is 24. The highest scoring word is program $ python3 highest scoring words.py Enter between 3 and 10 lowercase letters: a b e or at The highest score is 16. The highest scoring word is abator $ python3 highest scoring_words.py Enter between 3 and 10 lowercase letters: r a mm oxy The highest score is 17. The highest scoring words are, in alphabetical order: mayor moray moxa oryx $ python3 highest scoring_words.py Enter between 3 and 10 lowercase letters: eaeo rtsmn The highest score is 17. The highest scoring words are, in alphabetical order: matrons. transom 5
Step by Step Solution
★★★★★
3.39 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started