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,& ...



  1. Create a Python script file 
  2. 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:
    1. function welcome() that introduces the program.
      1. It does not take any argument and does not return any values.
      2. This program helps find surnames that contain your favorite letters.
    2. function get_letters() that does not take any arguments and returns a string that represents the user's favorite letters.
      1. It should repeatedly ask the user for a string that contains the list of favorite letters that the user wants in a surname. 
      2. It should check the input string to ensure that the user only provides letters between a-z. 
      3. It should not allow spaces, special symbols or numbers. 
      4. It should convert the input string to all uppercase and return it.
    3. function get_names() takes in a string fave_letters as a parameter and return a list of strings
      1. It should make an empty list called surnames
      2. It should open the file surnames.txt
      3. It should read each surname into variable name.
      4. For each name, it should check the fave_letters string and see if each letter in fave_letters is contained in name.
        1. If yes, name should be added to my_surnames.
      5. The function should return my_surnames
    4. 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.


We have an Answer from Expert

View Expert Answer

Expert Answer


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe