0% found this document useful (0 votes)
2 views8 pages

HW05

Homework 5 for CS 1301 focuses on tuples and modules, requiring students to implement five specific functions related to various scenarios. The assignment is due on February 22nd, 2024, and emphasizes individual work with resources available for assistance. Students must follow specific coding guidelines, including commenting out function calls and utilizing a provided skeleton file.

Uploaded by

emenyem283
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

HW05

Homework 5 for CS 1301 focuses on tuples and modules, requiring students to implement five specific functions related to various scenarios. The assignment is due on February 22nd, 2024, and emphasizes individual work with resources available for assistance. Students must follow specific coding guidelines, including commenting out function calls and utilizing a provided skeleton file.

Uploaded by

emenyem283
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Homework 5 - Tuples and Modules

CS 1301 - Intro to Computing - Spring 2024

Important

Due Date: Thursday, February 22nd, 11:59 PM.


This is an individual assignment. High-level collaboration is encouraged, but your
submission must be uniquely yours.
Resources:
TA Helpdesk
Email TA's or use class Ed Discussion
How to Think Like a Computer Scientist
CS 1301 YouTube Channel
Comment out or delete all function calls. Only import statements, global variables, and
comments are okay to be outside of your functions.
Read the entire document before starting this assignment.

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:

Test failed: False is not true

Written by: Avinash Palliyil, Vaidehi Rathod, & Paige Holland


Helpful Information to Know

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.

Importing the module itself:

import math
val = math.pi * math.sqrt(4)

Importing specific item(s) from a module:

from math import pi, sqrt


val = pi * sqrt(4)

Importing a module with a different name:

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!" .

>>> badges = [("Enthusiasm Patch", 6), ("Honesty Patch", 5),


("Beekeeping Patch", 10)]
>>> helpPhineas("Honesty Patch", badges)
'Hey Phineas! How can we help?'

>>> badges = [("Aeronautic Patch", 6), ("Marshmallow Patch", 5),


("I Just Saw A Cute Boy Patch", 64)]
>>> helpPhineas("I Just Saw A Cute Boy Patch", badges)
"We can't go see Phineas today!"
The Inator-Inator
Function Name: scrambleInator()
Parameters: instructions ( list )
Returns: scrambledInstructions ( list )
Description: Perry the Platypus has just uncovered Dr. Doofenshmirtz's plans for the complicated
Inator-Inator, prompting Perry to counter with his own creation, the Scramble-Inator.

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.

>>> instructions = ['Locate the big, red button labeled "Activate."',


'Turn the large dial to select the adventure setting:',
'Stand back and watch as the Inator-Inator works its magic.',
'Locate the "Whiz-Banginator" lever and pull it down swiftly.']
>>> scrambleInator(instructions)
['Agent P was here >:)',
'Stand back and watch as the Inator-Inator works its magic.',
'Turn the large dial to select the adventure setting:',
'Locate the big, red button labeled "Activate."']

>>> instructions = ['Search for the inconspicuous lever labeled "Activate."',


'Give it an unnecessarily dramatic pull with an evil laugh.',
'Spin the wheel to select your preferred mode of malevolence.',
"Revel in the chaos you've unleashed.",
'Observe the confused citizens of the Tri-State Area.',
'Concoct a story about a platypus thwarting your plans.']
>>> scrambleInator(instructions)
['Agent P was here >:)',
'Observe the confused citizens of the Tri-State Area.',
"Revel in the chaos you've unleashed.",
'Spin the wheel to select your preferred mode of malevolence',
'Give it an unnecessarily dramatic pull with an evil laugh.',
'Search for the inconspicuous lever labeled "Activate."']
104 Days of Summer Vacation But Even More Inventions!
Function Name: numInventions()
Parameters: inventions ( list )
Returns: completed ( int )
Description: Phineas and Ferb are working on a project that involves organizing information about
their inventions.

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!" .

>>> inventions= [["Time Machine", True], ["Anti-Gravity Ray", False],


["Giant Rollercoaster", True], ["Shrinkinator", False]]
>>> numInventions(inventions)
2

>>> inventions= [["Super Robot", True], ["Invisible Cloak", True],


["Teleportation Device", True], ["Mind-Reading Helmet", True],
["Laser Beam Glasses", True]]
>>> numInventions(inventions)
5
Emergency! Pick an Agent!
Function Name: agentDispatch()
Parameters: villian ( str ), coordinates ( tuple ), agents ( list )
Returns: secretAgent ( str )
Description: Your friend Carl, the usual operations manager at Organization Without An Acronym
(O.W.C.A), is ill and needs your assistance in selecting agents to dispatch.

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.

>>> agents = [('Agent P', (2, 5), 'Dr. Doofenshmirtz'),


('Agent C', (4, 2), 'Aloyse Von Roddenstein'),
('Agent H', (-2, 12), 'None'),
('Agent G', (205, 300), 'None'),
('Agent M', (1, 1), 'Jerry The Platypus')]
>>> agentDispatch('Dr. Doofenshmirtz', (6, 5), agents)
'Agent P'

>>> agents = [('Agent P', (2, 5), 'Dr. Doofenshmirtz'),


('Agent C', (4, 2), 'Aloyse Von Roddenstein'),
('Agent H', (-2, 12), 'None'),
('Agent G', (205, 300), 'None'),
('Agent M', (1, 1), 'Jerry The Platypus')]
>>> agentDispatch('Alien-inator', (1,1), agents)
'Agent M'
Build Inator
Function Name: perryAttack()
Parameters: inators ( list ), disguise ( tuple )
Returns: message ( str )
Description: As an evil intern for Dr. Doofensmirtz, your job is to choose an inator using the ina‐
tor.py module. Before utilizing any functions from this module, make sure to read the documenta‐
tion provided for each function.

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!" .

>>> perryAttack(['Shrink', 'Mind-Control', 'Picture'], ('plumber', False))


A platypus plumber?
'Behold! The Shrink-inator!'

>>> perryAttack(["Evil Baking Soda and Vinegar Volcano", "Pizzarium", "Papercut"],


("doctor", True))
Perry the Platypus doctor!
'Behold! The Evil Baking Soda and Vinegar Volcano-inator!'
Grading Rubric

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.

You might also like