Question: Please write a program in Python 3. Please show all output. Below is a code skeleton of a CLI program to test the functions in

Please write a program in Python 3. Please show all output.

 Below is a code skeleton of a CLI program to test the functions in HW3.py In it, you will write test functions for each of the functions from the module HW3.py . Each test should verify that the function it is testing works correctly. If it does, then the test function should return True , else it should return False . Don't just use the tests from the interactive examples. Think about what the function is supposed to do, and make sure to test not only that, but what it might do in unusual circumstances. (*See note below) Use argparse to implement the CLI portion of the program so it works as shown below. Output from the program should look like this when you use the -h help flag: $ python HW3_test.py -h usage: HW3_test.py [-h] [-u] [-w] [-l] optional arguments: -h, --help show this help message and exit -u, --unique Flag to test the unique function from HW3 -w, --words Flag to test the words_containing function from HW3 -l, --len Flag to test the len_test function from HW3 If no arguments are given, the program should do nothing. Since there are only flags (ie, no string arguments as in the lecture examples), you will need to check the argparse documentation to see how to implement flag arguments. ######################################################## ###Program Example: import argparse from HW3 import words_containing, len_test, unique def test_unique(): """Return True/False if the test of unique passes/fails"""  def test_words_containing(): """Return True/False if the test of words_containing passes/fails"""  def test_len_test(): """Return True/False if the test of len_test passes/fails"""  if __name__ == "__main__": parser = argparse.ArgumentParser() # Set up argparse information here # Based on user input, run test(s) requested and report outcome 

show output.

##################################################################################

##################################################################################

##HW3.py: Example:

def unique(iterable): """Yield iterable elements in order, skipping duplicate values.""" def words_containing(sentence, letter): """ Given a sentence, returns list of words that contain the letter.  Letter given is lowercase. Sentence can be mixed case, and the  case should be ignored for searching.  """  # Splitting the word words = sentence.split() # Declaring the list to store words that contains the letter contains = [] # Iterating through all the words for i in words: # Checking whether the letter is present in the lowercased word if letter in i.lower(): # Added word to list contains.append(i) print(contains) sentence = input("Enter the sentence: ") char = 'a' words_containing(sentence, char) 

#################################################################################

HW3.py actual code :

#Example Function:  """def words_containing(sentence, letter): 'Given a sentence, returns list of words that contain the letter. Letter given is lowercase. Sentence can be mixed case, and the case should be ignored for searching.'""" ############################################################################### #Part I Answer:  def words_containing(sentence, letter): """ Given a sentence, returns list of words that contain the letter.  Letter given is lowercase. Sentence can be mixed case, and the  case should be ignored for searching."""  # Splitting the word  words = sentence.split() # Declaring the list to store words that contains the letter  contains = [] # Iterating through all the words  for i in words: # Checking whether the letter is present in the lowercased word  if letter in i.lower(): # Added word to list  contains.append(i) #Printing  print(contains) sentence = input("Enter the sentence: ") char = 'a' words_containing(sentence, char) ##########################################################################################3 ################################################################################################ #Part II Directions  """ 1. Use exception handling for this one. 2. What happens when you try to get the len of something that has no len?""" """ Test in the REPL: >>> from HW3 import len_test >>> my_dict = {'a': 23, 'b': 8} >>> print(len_test(my_dict)) # should return: 2 >>> print(len_test(7)) # should return: -1 >>> print(len_test("")) # should return: 0 """ ################################################################################## #Parrt II Answer: def len_test(obj): """Return length of object or -1 if object has no length.""" def len_test(obj): """Return length of object or -1 if object has no length."""  if obj == "": return 0  else: try: length = len(obj) return length except: return -1  print(len_test("")) my_dict = {'a': 23, 'b': 8} print(len_test(my_dict)) print(len_test(7)) ################################################################################################ #Part III Directions: """ 1. Create a generator that loops over the input iterable, yielding one element one at a time, but skipping duplicates. Note: the output should be in the same order as the input iterable. """ #Example in REPL: """ Test in the REPL: >>> from HW3 import unique >>> numbers = [4, 5, 2, 6, 2, 3, 5, 8] >>> nums = unique(numbers) >>> next(nums) # should return: 4 >>> next(nums) 5 >>> next(nums) 2 >>> next(nums) 6 >>> next(nums) 3 >>> next(nums) 8 >>> next(nums) Traceback (most recent call last): File "", line 1, in  StopIteration >>> You can also test it quickly with: >>> list(unique(numbers)) # should return: [4, 5, 2, 6, 3, 8] """ # ######################################################################################### #Part III Answer:  def unique(lst): """Yield iterable elements in order, skipping duplicate values."""  tempList = list() for x in lst: if x in tempList: continue  tempList.append(x) yield x 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!