Home /
Expert Answers /
Computer Science /
create-a-python-script-file-nbsp-you-will-write-a-program-that-will-read-in-a-file-of-last-names-pa798
(Solved):
Create a Python script file
You will write a program that will read in a file of last
names,& ...
Create a Python script file
You will write a program that will read in a file of last
names, surnames.txt and print out the
names that contain the user's favorite letters in ascending order
by name length. It should consist of several
functions:
function welcome() that introduces
the program.
It does not take any argument and does not return any
values.
This program helps find surnames that contain your favorite
letters.
function get_letters() that does not
take any arguments and returns a string that represents the user's
favorite letters.
It should repeatedly ask the user for a string that contains
the list of favorite letters that the user wants in a
surname.
It should check the input string to ensure that the user only
provides letters between a-z.
It should not allow spaces, special symbols or
numbers.
It should convert the input string to all uppercase and return
it.
function get_names() takes in a
string fave_letters as a parameter and
return a list of strings
It should make an empty list
called surnames
It should open the file surnames.txt
It should read each surname into
variable name.
For each name, it should check
the fave_letters string and see if each
letter in fave_letters is contained
in name.
If yes, name should be added
to my_surnames.
The function should
return my_surnames
function main() does not take any
arguments and does not return any values.
It will call
the welcome() function.
It will call
the get_letters() function
and store the value in the
variable my_fave_letters. my_fave_letters is
all uppercase.
It will call
the get_names() function
with my_fave_letters as an
argument. It will store the return value in the
variable my_surnames.
It will go through
the my_surnames list and build a
dictionary called name_length which
contains key/value pairs of names and the length of the
name. For example: {'FRANKLIN': 9}
It will print out
the name_length dictionary, so the user
can see the names and name lengths. It does not have to be in
order.