Define a functionthat takes a string containing a filename


With test file and in simple python form:

Define a functionthat takes a string containing a filename for the keys of the dictionary, and an optional integer, the maximum number for the values of the dictionary, and returns a dictionary using the words in the file as keys and random numbers, from 0 up to the maximum number, as the values.

Do not use the methods .read() or .readlines(). You should be reading through the file one line at a time (using a for loop, or uisng a whileloop with .readline(). If there is a problem working with the file, your function should return an empty dictionary. But note that you should only be catching exceptions that involve working with the file, not all exceptions.

The maximum number argument is optional, and if the function is called without a second argument it should use 10 as the maximum value.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Define a functionthat takes a string containing a filename
Reference No:- TGS02945012

Expected delivery within 24 Hours