Data Types
Argparse
Code Questions
Functions
More on Argparse
100

type=float means that my data must be what?

A number with a decimal

100

Name two benefits of using the argparse module

Simplifies defining and parsing command-line arguments

Help and usage messages

Default Values

Data Type Assignment

100

What should you do if your code throws an error?

Check the error code, look for underlined code, debug, research, peer review, etc.

100

What is our visual cue that something is a function in Python?

Snake naming convention

()'s give half points

100

What are the required arguments when running this script?

--name

--new-grade

200
What is the data type given to true/false or on/off values?

Boolean

200

Where does a user type their arguments into to utilize the argparse module?

The CLI

200

What happens if I delete the 'f' in the code below?

print(f"{args.name}'s updated GPA is: {updated_gpa}")

The variables are not able to be called and they print as plain text.

200

def calculate_new_gpa(previous_gpa, new_grade, credits, name, verbose):

What are we doing with this line of code?

Defining a new function

200

Why do we use dashes between words in long option flag names like:

--new-grade?

Because if we don't, Python will see the space as the input of that flag's argument

300

True or False: A float can be an integer but an integer cannot be a float

False! 

300

What is the line of code needed to import the argparse module?

import argparse

300

What happens if we code 'required=true' into our argument? Do not say it makes it required....

It makes the user enter the argument no matter what, the user is given a help message when they don't enter what was needed, the script will not run without that argument.

300

def calculate_new_gpa(previous_gpa, new_grade, credits, name, verbose):

What are 'new_grade' and 'name' examples of if they are inside those parenthesis?

arguments

300

What benefit does using flags give us?

Flexibility in using arguments on CLI
400

What is wrong with the syntax of this if it were inside of the parenthesis while adding an argument?

type="str"

There shouldn't be quotes there

400

Where does this module need to be imported within your script?

At the top!

400

What is the reason we use this line of code?

if __name__ == "__main__":

This ensures that the code inside it only runs when the script is executed directly, not when it's imported as a module.

400

Why would we include an if/elif/else code block in a function?

Progressive error handling

400

What does metavar="GRADE" do?

It shows a different variable name in the help messages, makes things easier to interpret.

500

What is the default data type given to argument inputs using the argparse module?

string

500

True or False: The argpase module is a built-in module maintained by the Python Standard Library.

True

500

In lines 24-30, what can be removed?

type=str

500

What does the argument 'verbose' do in this script?

verbose is a command-line flag that, when included, sets args.verbose to True. In this script, it turns on extra print statements that show the step-by-step GPA calculation. If you don’t include it, args.verbose is False, and the script just prints the final GPA.

500

What does the code below do?

help="Print detailed calculation steps"


It provides more information for users when they use the help argument. (-h or -help)