Question: PYTHON PROGRAMMING LANGUAGE PART 4 parse_args() Parameters a list of strings containing the command line arguments for the program (when you call this program, you

PYTHON PROGRAMMING LANGUAGE

PART 4

parse_args()

Parameters

a list of strings containing the command line arguments for the program (when you call this program, you will pass sys.argv[1:] as the argument for this parameter)

Functionality

Create an instance of the ArgumentParser class from the argparse module Use the add_argument() method of your ArgumentParser instance to add the following arguments: Required arguments (i.e., the user can't run the program without specifying these): the total amount of the mortgage (as a float) the annual interest rate (as a float; should be between 0 and 1) Optional arguments (i.e., the user can choose to specify these or omit them and use the default values): the term of the mortgage in years (as an integer; default value: 30) the number of payments per year (as an integer; default value: 12) the target payment amount (as a float; default value: None) Use the parse_args() method of your ArgumentParser instance to parse the list of strings that was passed to your function; this will result in a namespace object, which you should return

Note

You will need to import argparse and sys, or at least parts of these modules, in order for this function to work properly. Remember, import statements belong at the top of your script, right after the script docstring.

After your function definitions, you should have an if __name__ == "__main__": statement in which you do the following: pass sys.argv[1:] to parse_args() and store the result in a variable call the main() function; pass in the total amount of the mortgage, the annual interest rate, the term of the mortgage, the number of payments per year, and the target payment amount using the values extracted from the command line arguments by your parse_args() function

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!