Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix my coding in python for as criteria below. I just only want to print exactly same as in expected output not all words.

Please fix my coding in python for as criteria below.

image text in transcribed

I just only want to print exactly same as in "expected output" not all words.

Also please fix code for the function find_all_possible_combinations as all of pytest

image text in transcribed

image text in transcribedAnd also the function "add_digit" and "display_possible_words

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

Thank you

1.1 Running the script from the command line with valid arguments shall result in the script producing a well formatted, correct, output xpected output i Actual output 1. 43556 : gekko 1. All orders: 2. '.'.'. hello 2. { ' 43556 '\} 3. 4. All words: 5. ['a', , 'aa' , ' aaa' , 'aah' , ' aahed', , 'aahing', ' 'aahs', , 'aal', , 'aalii', , 'aaliis' , 'aals', , 'aam', ' aani ', ' 'aardvark', , 'aardvarks' , ' 'aardwolf', , 'aardwolves' , ' aargh' , ' 'aaron' , ' 'aaronic' , . ' aaronical', ' aaronite', ' 'aaronitic' , 'aarrgh', , 'aarrghh' , ' 'aru', ' 'as' , ' 'aasvogel' , 'aasvogels', ' 'ab', , 'aba' , ' 'ababdeh' , 'ababua' , ' 'abac', ' 'abaca' , 'abacay', ' 'abacas' , ' 'abacate', ' abacaxi' , ' 'abaci', ' 'abacinate' , 'abacination' , 'abacisci' , ' 'abaciscus', ' 'abacist', , 'aback', 'abacli', ' 'abacot' , ' abacterial', ' 'abactinal', ' abactinally' , ' 'abaction' , ' abactor', 'abaculi', , 'abaculus', , 'abacus' , ' abacuses', ' 'abada' , ' 'abaddon' , ' 'abadejo' , ' 'abadengo' , 'abadia', ' 'abadite', ' 'abaff', ' abaft', ' 'abay' , ' abayah', , 'abai sance', ' abaised', ' abaiser', 'abaisse', 'abaissed', 'abaka', 'abakas', 'abalation', 'abalienate', 'abalienated', 4 Testing the find_all_possible_combinations function Results Output pytest (1/3) test_find_all_possible_combinations Calling the function with an empty order_number string test_find_all_possible_combinations Calling the function with a valid order_number '23' shall (') shall result in an empty list being returned result in a list of all possible combinations using the digits in the order_number (digits keep the same order as in the order_number) test_find_all_possible_combinations Calling the function with a valid order_number '34546' AssertionError: shall result in a list of all possible combinations using the digits in the order_number (digits keep the same order as in the order_number) ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'] AssertionError: Expected the function to return: But got: ['dgjgm', 'dgjgn', 'dgjgo', 'dgjhm', 'dgjhn', 'dgjho', 'dgjim', 'dgjin', 'dgjio', 'dgkgm', 'dgkgn', 'dgkgo', 'dgkhm', 'dgkhn', 'dgkho', 'dgkim', 'dgkin', 'dgkio', [ ] 'dglgm', 'dglgn', 'dglgo', 'dglhm', 'dglhn', 'dglho', 'dglim', 'dglin', 'dglio', test_add_digit Calling the function with ' 2 ' and '[]' should result in the function returning test_add_digit Calling the function with ' 3 ' and '['a', 'b', 'c']' should result in the function '['a', 'b', 'c']' returning '['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']' TypeError: 'int' object is not iterable TypeError: 'int' object is not iterable 1. E TypeError: 'int' object is not iterable 1. E TypeError: 'int' object is not iterable test_add_digit Calling the function with '6' and '['d', 'e', 'f']' should result in the function returning '['dm', 'dn', 'do', 'em', 'en', 'eo', 'fm', 'fn', 'fo']' TypeError: 'int' object is not iterable 1. E TypeError: 'int' object is not iterable test_display_possible_words Verifying that calling the function with order_number = '23456' and words = '['abcde', 'qwert']' results in the correct output TypeError: display_possible_words() takes positional arguments but 2 were given 1. E TypeError: display_possible_words() takes positional arguments but 2 were given A few weeks ago, you managed to get yourself a job at a local warehouse where you collect goods for the regular customers. Each evening you collect what the customers have ordered for the next day. It is an easy job that pays well and you are really happy about it, but there is one problem. All orders have a unique identifier called order number that consists of five digits, and you can not help yourself from trying to translate the order number into a real word each time you pick up a new order. For example, if you get the order number 78676 you might translate it into the word storm (explanation below). You always try to find a translation before you finish collecting the goods for an order but sometimes it is too tricky, and for this reason you would like to create a script that can solve the translation for you. By sheer luck it turns out that the system at work can email you a file with all the order numbers you have picked in a day. You want your script to take two filenames (full path) as command line arguments. The first argument shall be the file with the order numbers and the second argument shall be a file with words in it. The script shall look at the file with the order numbers and for each order number in the file, it shall try to find all the words that can be constructed using those digits. The words must be proper words listed in the file linked by the second command line argument. The file with words in it shall be a regular text file with one word per line and the file with all the order numbers shall be a file that contains a pickled Python Set that stores all the order numbers as strings All the possible words for each order number shall be displayed on the screen using this exact format: The translation from digits to letters shall be done using the ITU E.161 /SO99958 standard. This is the same standard used when you use the keypad on a phone to translate from digits to letters. The following picture shows the translation scheme: script must implement the following functions and constants: TRANSLATION This is a global constant that contains a dictionary. The dictionary shall store the digits 0 - 9 as keys (stored as strings) and their corresponding value shall be the letters represented by each digit according to the ITU E.161/ISO 9995-8 standard. The letters shall be stored in one string without any spaces in between the individual letters. For example, {2 ': 'abc' }. read_orders(filename) Opens the file linked by the string filename. Using pickle the function reads, and returns, the Set of order numbers stored in the file. If the filename is invalid the function shall raise a FileNotFoundError. read_words(filename) Creates a list that is populated with all the words read from the file linked by the string filename. The file stores one word on each line. The list of all the words shall be returned from the function. If the filename is invalid the function shall raise a FileNotFoundError. find_all_possible_combinations(order_number) The overarching goal of this function is to return all the possible combinations that can be achieved using the digits in the order_number string. The output shall be a list of strings. An example of how this function works can be seen below: input: '23' output: ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'] Another way of looking at how this function works is to have a look at the following image: Another way of looking at how this function works is to have a look at the following image: add_digit(digit, combinations) This function shall be used by find_all_possible_combinations. The two parameters are the next digit to add and the current collection of combinations found. The functionality is best described with an example where we try to find all combinations for ' 23 ': First call to function: Input: ' 2 ' and [] Output: ['a', 'b', 'c'] Explanation: ' 2 ' is the first digit in the number we want to translate and the empty list is because we do not have any previous combinations yet. The output is all the different letters we can get by translating ' 2 ' into letters. Second call to function: Input: '3' and ['a', 'b', 'c'] Output: ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'] Explanation: ' 3 ' is the second digit in the number we want to translate and the ['a', 'b', 'c'] is from the output in the first step, or in other words, our previously found combinations. The output is all the different combinations of letters we can get by first translating a ' 2 ' and then a ' 3 '. Second call to function: Input: '3' and ['a', 'b', 'c'] Output: ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'] Explanation: ' 3 ' is the second digit in the number we want to translate and the ['a', 'b', 'c'] is from the output in the first step, or in other words, our previously found combinations. The output is all the different combinations of letters we can get by first translating a ' 2 ' and then a '3'. filter_valid_words(possible_combinations, valid_words) The parameter possible_combinations is a list of strings that contain all the possible combinations of letters you can and the valid_words parameter is also a list of strings but it contains all the valid, real, words read from the word list file sent as a command line argument to the script. The function shall return a list with all combinations from possible_combinations that also exists in valid_words. display_possible_words(order_number, words) This function is responsible for displaying one order_number and the potential real words it can translate into. The information shall be displayed on the format described earlier in the task. main() Uses the command line arguments to read the files with the order numbers and words, and then loops through all the order numbers, finds all the in the script displaying the following message to the user if any of the files given as command line arguments are not valid: if mame main()name= _main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

Provide several definitions of risk perception and risk tolerance.

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Define policy making?

Answered: 1 week ago

Question

Define co-ordination?

Answered: 1 week ago

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago