Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write the follwing program in Python 3. Please show all outpout. Below are test to be designed based on the programs. Each test should

Please write the follwing program in Python 3. Please show all outpout.

Below are test to be designed based on the programs. Each test should return True, lese it should return false. Don't just use tst from the interactive examples. Think about what function is supposed to do do, and make sure to test not only that, but what it might do in unusual circumstanacces.

Use argparse to implement the CLI portion ofthe 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, --hlep 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 flages 9ie, no string arguments as in the lecture examples), you

will need to check the argparse documentation to see how to implement flag arguments.

#######################################################################################3 def test_unique(): """Return True/False if the test of unique passes/fails""" Actual Program: 
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 

#########################################################################################3

def test_words_containing(): """Return True/False if the test of words_containing passes/fails""" Actual Program: 
art 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 words to contains  contains.append(i) #Printing  print(contains) sentence = input("Enter the sentence: ") char = 'a' words_containing(sentence, char) 

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

def test_len_test(): """Return True/False if the test of len_test passes/fails""" Actual Program: 
ef 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)) 
#####################################################################################################3 if __name__ == "__main__": parser = argparse.ArgumentParser() # Set up argparse information here # Based on user input, run test(s) requested and report outcome 

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

More Books

Students also viewed these Databases questions

Question

Write an elaborate note on marketing environment.

Answered: 1 week ago