More on Modules
Code Questions
Syntax
Flags
100
A module that allows you to collect input via positional arguments on the command line

What is the sys module (will also accept sys.argv).

100

The importing of the argparse module occurs on this line.

What is line 3

100

What is the syntax required to define an argument using the argparse module?

parser.add_argument()

100

What does a flag do?

Assigns an identity to an argument, allows users to choose what order they enter arguments

200

A module that allows your script to run shell commands from within the script via a temporary bash shell.

What is the subprocess module 

200

What is happening on line 22?

The parser is being created which allows the script to have arguments defined. The description in the inside is optional but shown when --help flag is used.

200

The keyword argument that determines whether a user must enter something or not on the command line interface?

What is Required=true/false

200

What might be the short option flag for --name?

-n

300

**DAILY DOUBLE**


A module that provides low-level networking interfaces.

What is the socket module.

300

What is happening on lines 48-54?

An argument is being created with the long option flag --credits, type assigned as float, default set to 15.0, adding help information, and assigning the argument a user-friendly name of CREDITS.

300

The keyword argument that assigns a value to an argument if the user does not?

What is default=

300

Can an argument have more than one of each type of flag?

Yes

400

A module that allows you to collect input via flagged arguments on the command line.

What is the argparse module.
400

What is the benefit of line 51 and why don't we see that same parameter defined in the argument for --new-grade?

A default value is being set in case the user doesn't enter their amount of credits. This isn't in the --new-grade argument because that would defeat the purpose of the script's function.

400

The only data type that we do not have to explicitly define.

What is type=str

-or-

string

400

Why would we use the long vs short options of flags?

Usability

500
The line of code required to ensure your script will only run if it is executed directly but not when imported as a module.

What is 

if __name__="__main__":

500
We see the term verbose a few times in this script, is it an argument or a built-in variable?

It is an argument defined on lines 56-60. Verbose is a common term used in programming to flag the argument that controls how much output information is displayed.

500

What is missing in the line of code below?

def calculate_new_gpa(previous_gpa new_grade credits name verbose)

Commas and the colon (, & :)

500

Are flags required in arguments?

No, but excluding flags takes away some of the magic of the argparse module. Without flags, users must enter arguments in the exact order they are coded in our script.

M
e
n
u