0% found this document useful (0 votes)
1 views7 pages

HW04

Homework 4 for CS 1301 focuses on implementing functions using strings and lists, with a due date of February 15th, 2024. The assignment includes five specific functions to code, each with detailed descriptions and examples. Students are encouraged to collaborate but must submit their unique work, and the grading will be based on the functionality of the implemented functions.

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)
1 views7 pages

HW04

Homework 4 for CS 1301 focuses on implementing functions using strings and lists, with a due date of February 15th, 2024. The assignment includes five specific functions to code, each with detailed descriptions and examples. Students are encouraged to collaborate but must submit their unique work, and the grading will be based on the functionality of the implemented functions.

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/ 7

Homework 4 - Strings and Lists

CS 1301 - Intro to Computing - Spring 2024

Important

Due Date: Thursday, February 15th, 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 assignment is to practicing implementing functions using lists and string methods.
The homework is composed of 5 functions for you to code and execute. You have been given the
HW04.py skeleton file to fill out. Please read this PDF thoroughly as you will find more detailed in‐
formation to complete your assignment. Remember to turn in the HW04.py file as your final sub‐
mission on Gradescope.

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: Jane Crowley, M. Hamzah Zahid, & Paige Holland


Case Count of Love Letter
Function Name: countCase()
Parameters: loveLetter ( str )
Returns: difference ( str )
Description: You're crafting a love letter, and you want every sentence to be as harmonious as our
hearts – with an equal number of uppercase and lowercase letters! Write a function called count‐
Case() that takes in one parameter: a sentence from a love letter ( str ).

If the number of uppercase letters outnumber the lowercase ones, then return the string
"Darling, I need {difference} more lowercase character(s) in our love story."
If the lowercase letters outnumber the uppercase ones, then return the string "Sweetheart, I
need {difference} more uppercase character(s) in our love tale."
If both cases are equal, then return the string "Our love story is perfectly balanced,
just like us." .

Note: Consider digits, blank spaces, or special characters within the love letter to have no case.

>>> countCase("You are my MOON!")


'Sweetheart, I need 2 more uppercase character(s) in our love tale.'

>>> countCase("U + m3 = <3")


'Our love story is perfectly balanced, just like us.'
Valentine Decryption
Function Name: decryptValentine()
Parameters: encryptedMessage ( str ), key ( int )
Returns: decryptedMessage ( str )
Description: You've just received a valentine encrypted with a cipher key! Write a function called
decryptValentine() that takes in two parameters: the encrypted message ( str ) and the cipher
key ( int ). Return the decrypted message by combining the characters at index positions that are
multiples of the key, and then finally reversing the string.

>>> decryptValentine("u1o3y4 3e5v0o2L", 2)


'Love you'

>>> decryptValentine("!o2t67r12a!!ejkH", 3)
'Heart!'
Match Finder
Function Name: findLove()
Parameters: candidates ( list ), favCity ( str ), favColors ( list )
Returns: matches ( list )
Description: Love is in the air, and you're on a quest to find the perfect match! Write a function
called findLove() that takes in three parameters: a list of potential candidates ( list ), your fa‐
vorite city ( str ), and a list of your favorite colors ( list ). Each candidate is represented as a list
containing their name ( str ), the city they reside in ( str ), and their favorite color ( str ).
Determine and return a sorted list of the names of potential matches who share the same favorite
city with you and have a favorite color that is among your selected favorite colors.

>>> candidates = [["Joey", "NYC", "blue"], ["Chandler", "NYC", "green"]]


>>> favCity = "NYC"
>>> favColors = ["green", "pink", "blue"]
>>> findLove(candidates, favCity, favColors)
['Chandler', 'Joey']

>>> candidates = [["Eric", "Denver", "red"], ["Kyle", "Denver", "yellow"],


["Stan", "Atlanta", "blue"]]
>>> favCity = "Atlanta"
>>> favColors = ["yellow", "orange", "red"]
>>> findLove(candidates, favCity, favColors)
[]
Mutual Interests
Function Name: mutualInterests()
Parameters: yourInterestsList ( list ), theirInterestsLists ( list )
Returns: interests ( list ) or message ( str )
Description: You're looking to see if you are compatible with a new match! Write a function called
mutualInterests() that takes in two parameters: your list of interests ( list ) and your match's
list of interests ( list ). Return a list containing the interests you both share, sorted in alphabetical
order. If you have no mutual interests, then return the string "Not a match!" .

>>> yourInterestsList = ["dance", "movies", "music"]


>>> theirInterestsLists = ["movies", "music"]
>>> mutualInterests(yourInterestsList, theirInterestsLists)
['movies', 'music']

>>> yourInterestsList = ["basketball", "music"]


>>> theirInterestsLists = ["music", "basketball", "swimming"]
>>> mutualInterests(yourInterestsList, theirInterestsLists)
['basketball', 'music']
Galentine's Day!
Function Name: galentines()
Parameters: restaurants ( list ), friends ( list ), friendRestaurants ( list )
Returns: friendsList ( list )
Description: You wants to plan a date out with your friends for Galentine's Day, but you want en‐
sure that they like the same restaurants as you do in Atlanta. Write a function called
galentines() that takes in three parameters: a list of the restaurants you like ( list ), a list of
your friends ( list ), and a nested list of the restaurants your friends like ( list ). If a friend shares
a favorite restaurant with you, then you would love to go with them. Return a list of the friends you
would love to go with, sorted in alphabetical order. However if no friends share enough of your fa‐
vorite places, then print "It's just another day alone." and return an empty list.

Note: The names in the friends list correspond to the restaurant list of the same index in
friendRestaurants.

>>> restaurants = ["Cypress Street", "Atwoods", "Moe's"]


>>> friends = ["Lasya", "Ramya", "Harshith"]
>>> friendRestaurants = [["Cypress Street", "Atwoods"], ["Atwoods", "Chipotle"],
["Moe's"]]
>>> galentines(restaurants, friends, friendRestaurants)
['Harshith', 'Lasya', 'Ramya']

>>> restaurants = ["Cheba Hut"]


>>> friends = ["Chris", "Alice", "Jane"]
>>> friendRestaurants = [["Atwoods"], [], ["Tin Drum"]]
>>> galentines(restaurants, friends, friendRestaurants)
It's just another day alone.
[]
Grading Rubric

Function Points

countCase() 20

decryptValentine() 20

findLove() 20

mutualInterests() 20

galentines() 20

Total 100

Provided
The HW04.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 HW04.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 HW04.py on Canvas.

You might also like