Answered step by step
Verified Expert Solution
Link Copied!

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 read_data that accepts
a string containing the name of a file on disk. The file contains 10,000 lowercase
words (1 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 0)
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. (6 marks)
PART B:
Write the code for a python function called part_of_word 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 {0:"catch", 1:"treacherous", 2:"crack", 3:"actor", 4:"back"}
and a search string of "tca" would return a list of:
["tca", catch", "treacherous", "actor"]
(14 marks).
# MAIN FUNCTION:
# program: studentID_PRG550X.232.LT1.py
# student: your name
# student number: your 9-digit student number
# date: june 16,2023
# purpose: solution to PRG550X Lab Test #1
# Your functions MUST be placed here...
# Your functions MUST be placed here...
import string
def main() :
d = read_data("dictionary.txt")
result = part_of_word(d, "yhpotn")
print(result)
result = part_of_word(d, "mez")
print(result)
result = part_of_word(d, "obtnle")
print(result)
result = part_of_word(d, "nxots")
print(result)
result = part_of_word(d, "eqrs")
print(result)
if __name__=="__main__" :
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

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

Step: 3

blur-text-image

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

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

How does an applicant apply?

Answered: 1 week ago