Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions

Question

Identify the cause of a performance problem. page 363

Answered: 1 week ago