type=float means that my data must be what?
A number with a decimal
Name two benefits of using the argparse module
Simplifies defining and parsing command-line arguments
Help and usage messages
Default Values
Data Type Assignment
What should you do if your code throws an error?
Check the error code, look for underlined code, debug, research, peer review, etc.
What is our visual cue that something is a function in Python?
Snake naming convention
()'s give half points
What are the required arguments when running this script?
--name
--new-grade
Boolean
Where does a user type their arguments into to utilize the argparse module?
The CLI
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.
def calculate_new_gpa(previous_gpa, new_grade, credits, name, verbose):
What are we doing with this line of code?
Defining a new function
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
True or False: A float can be an integer but an integer cannot be a float
False!
What is the line of code needed to import the argparse module?
import argparse
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.
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
What benefit does using flags give us?
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
Where does this module need to be imported within your script?
At the top!
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.
Why would we include an if/elif/else code block in a function?
Progressive error handling
What does metavar="GRADE" do?
It shows a different variable name in the help messages, makes things easier to interpret.
What is the default data type given to argument inputs using the argparse module?
string
True or False: The argpase module is a built-in module maintained by the Python Standard Library.
True
In lines 24-30, what can be removed?
type=str
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.
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)