Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Provide a complete solution to the following problems using the Python programming language. READ THE ENTIRE QUESTION ( AND THE EXAMPLE ) CAREFULLY BEFORE DEVELOPING
Provide a complete solution to the following problems using the Python
programming language.
READ THE ENTIRE QUESTION AND THE EXAMPLE CAREFULLY BEFORE DEVELOPING
YOUR SOLUTION!
PART A:
Write the code for a python function called readdata that accepts
a string containing the name of a file on disk. The file contains lowercase
words word per line This function reads all of the words in the file
and stores them in a python dictionary where the keys are integers starting at
and the values are the words.
The function returns the dictionary of words.
This function MUST use exceptional handling and the file must be closed after
it has been processed. marks
PART B:
Write the code for a python function called partofword that accepts a string and
the dictionary from PART A
This function returns a list containing every word in the dictionary that contains
ALL of the characters in the test string accepted as a parameter, including the test
string itself as the first element.
For example, a dictionary of :"catch", :"treacherous", :"crack", :"actor", :"back"
and a search string of "tca" would return a list of:
tca catch", "treacherous", "actor"
marks
# MAIN FUNCTION:
# program: studentIDPRGXLTpy
# student: your name
# student number: your digit student number
# date: june
# purpose: solution to PRGX Lab Test #
# Your functions MUST be placed here...
# Your functions MUST be placed here...
import string
def main :
d readdatadictionarytxt
result partofwordd "yhpotn"
printresult
result partofwordd "mez"
printresult
result partofwordd "obtnle"
printresult
result partofwordd "nxots"
printresult
result partofwordd "eqrs"
printresult
if namemain :
main
# OUTPUT:
yhpotn 'anthropology', 'pantyhose', 'python', 'telephony'
mez 'customize', 'customized', 'enzyme', 'magazine', 'magazines', 'maximize', 'minimize', 'mozambique', 'muze', 'optimize', 'zimbabwe'
obtnle 'biotechnology', 'celebration', 'convertible', 'rehabilitation', 'responsibilities', 'responsibility', 'troubleshooting'
nxots 'examinations', 'exceptions', 'exhibitions', 'expectations', 'extension', 'extensions'
eqrs 'enquiries', 'frequencies', 'headquarters', 'inquiries', 'prerequisite', 'quarters', 'queries', 'questionnaire', 'request', 'requested', 'requesting', 'requests', 'requirements', 'requires', 'square'
Step by Step Solution
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