A Keyword Argument is a NAME-VALUE Pair you pass to a function
You DIRECTLY associate the name and value within the argument so there's no confusion
This frees you from having to worry about order
#Define The Function: describe_minion
#=====================================
def describe_minion(minion_type, minion_name):
#Gru explains his new minion in a dramatic way
#================================================
print(f"\nOh ho ho! I have created a {minion_type}, because why not!")
print(f"And get this—my {minion_type}'s name is {minion_name.title()}! Mwahaha!")
print("Yes, I know, I’m a genius. But let’s be honest, it’s mostly luck.")
#Call The Function
#==================
describe_minion(minion_type='banana-loving minion', minion_name='kevin')
Look at how we defined the function: def describe_minion(minion_type, minion_name):
Look at how we called the function: describe_minion(minion_type='banana-loving minion', minion_name='kevin')
We EXPLICITLY gave value to the parameters in the call.
This way, we don't care about the order in the function definition
Our function needs 2 pieces of information to work, but we only passed in ONE piece of information
Write a Function that takes in a minion name and minion task, and print out a formatted table of the name and task:
def describe_minion(minion_task, minion_name):
# You Have To Write the Code
Call the function as shown:
describe_minion('yellow')
Let's redefine the function with default values and call it 3 different ways:
def describe_minion(minion_task='Babysitter', minion_name='bob'):
#Define Your Function Here
#Call The Function 3 Different Ways
describe_minion('Engineer', 'stuart')
describe_minion('green')
describe_minion( )
Explain what happened here
Did it work?
Were there errors?
Gru is preparing a secret mission, but sometimes he likes to leave out the details until the last minute. He wants to be flexible with the mission briefing, so you need to help him by using default values in Python functions. Let’s make sure the mission gets planned properly, even if Gru forgets a few details!
Tasks:
Write a function called mission_briefing() that accepts the following three parameters:
mission_name: The name of the mission. Default to "Top Secret" if not provided.
minion_name: The name of the lead minion. Default to "Bob" if not provided.
mission_tool: The tool for the mission. Default to "Freeze Ray" if not provided.
ONCE THIS IS WORKING:
Break this up into multiple functions
Display Name
Before this is run, give the user the option to put the name in
ALL CAPS
ALL LOWER
Title Case
Display Mission
Randomize a fun message when a mission is typed in
Display Tool
Random roll of dice to see if the minion forgot the tool he needed
Why would we do this??
We may want each section to process information differently. Functions are where we put LOGIC!!!
Task:
Use one of the programs you've already written, and change it to use the following:
Functions - Must have at least 2 to 3 functions
Keyword Arugments and Default Values
HAVE FUN WITH THIS!!!!