HW05
HW05
Important
The goal of this homework is for you to enhance your understanding of lists, tuples, and mod‐
ules. The homework will consist of 5 functions for you to implement. You have been given the
HW05.py skeleton file to fill out. However, below you will find more detailed information to com‐
plete your assignment. Read it thoroughly before you begin.
Hidden Test Cases: In an effort to encourage debugging and writing robust code, we will be in‐
cluding hidden test cases on Gradescope for some functions. You will not be able to see the input
or output to these cases. Below is an example output from a failed hidden test case:
Modules
Modules allow you to use code from another source. This could include other code that you've writ‐
ten in a different Python file, or external code written by other programmers. To use a module, you
must import it into your file first. There are multiple ways to do this. Let's look at some ways to im‐
port and use the pi constant and sqrt function from Python's built-in math module.
Note: By convention, import statements should be at the top of your file, not in a function.
import math
val = math.pi * math.sqrt(4)
import math as m
val = m.pi * m.sqrt(4)
Whatcha Doin?
Function Name: helpPhineas()
Parameters: badge ( str ), badges ( list )
Returns: consensus ( str )
Description: Isabella's crush on Phineas is no secret, but the other Fireside Girls worry she's de‐
voting too much time to helping him.
Write a function called helpPhineas() that takes in two parameters: the name of a badge ( str )
and a list of all badges ( list ). Each badge in the list is represented as a tuple containing the
badge name ( str ) and the number of times Isabella has earned it ( int ). If Isabella has more
than 8 or fewer than 1 of the specified badge, then she can't help Phineas. The function should re‐
turn "Hey Phineas! How can we help?" if she can help. Otherwise, return the string "We can't
go see Phineas today!" .
Write a function called scrambleInator() that takes in one parameter: a list of instructions
( list ). The function should remove the last instruction, reverse the order of the remaining instruc‐
tions, and add a special instruction, "Agent P was here >:)" , to the front of the list. Finally, re‐
turned the scrambled list.
Write a function called countCompletedInventions() that takes in one parameter: a list of inven‐
tions ( list ). Each invention is represented as a list with the invention name ( str ) and comple‐
tion status ( bool ). The function should return the number of completed inventions. If no inventions
have been completed, then return the string "We still have 104 days to invent something!" .
Write a function called agentDispatch() that takes in three parameters: the name of a villain
( str ), their coordinates ( tuple ), and O.W.C.A.'s available agents ( list ). Each agent in the list
is represented as a tuple containing their name ( str ), coordinates ( tuple ), and nemesis ( str ).
The function should return the name of an agent to dispatch. If an agent in the database's nemesis
is the villian, then return the nemesis's name. Otherwise, dispatch the agent closest to the villain's
location, calculated using the following distance formula: distance = sqrt((x_2 - x_1) ** 2 +
(y_2-y_1) ** 2) . If no agents are available to dispatch, then return the string "Sorry, no
agents available! Good luck defending O.W.C.A. HQ!" .
Note: You may assume no agents will be equally close and each agent will have a unique
nemesis.
Write a function called perryAttack() that takes in two parameters: a list of potential inators to
build ( list ) and Perry the Platypus's disguise ( tuple ). The disguise is represented as a tuple
containing the costume name ( str ) and whether it is currently being used ( bool ). If the boolean
indicates he's in disguise, then print the string "Perry the Platypus {costume}!" . Otherwise,
print the string "A platypus {costume}?" . Utilize the schemes() function to identify the inator
with the highest rating. Return the name of this inator with "-inator" appended to the end, like
this: "Behold! The {chosen inator}-inator!" .
Function Points
helpPhineas() 20
scrambleInator() 20
numInventions() 20
agentDispatch() 20
perryAttack() 20
Total 100
Provided
The HW05.py skeleton file has been provided to you. This is the file you will edit and implement.
All instructions for what the functions should do are in this skeleton and this document.
Submission Process
For this homework, we will be using Gradescope for submissions and automatic grading. When
you submit your HW05.py file to the appropriate assignment on Gradescope, the autograder will
run automatically. The grade you see on Gradescope will be the grade you get, unless your grad‐
ing TA sees signs of you trying to defeat the system in your code. You can re-submit this assign‐
ment an unlimited number of times until the deadline; just click the “Resubmit” button at the lower
right-hand corner of Gradescope. You do not need to submit your HW05.py on Canvas.