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 practice and understand how to write and use loops and iteration. The homework will consist of 5 functions for you to implement. You have been given HW03.py skeleton file to fill out. However, below you will find more detailed information to complete your assignment. Read it thoroughly before you begin.
Hidden Test Cases: In an effort to encourage debugging and writing robust code, we will be including 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:
Written by Assata Quinichett (aquinichett@gatech.edu), Grace McDonough
(gmcdonough3@gatech.edu), and Alex King (aking1@gatech.edu)
Helpful Methods
A method is a special type of function that we'll cover in more detail later on in the course. All you need to know for this homework is that methods are called through the . operator on a string or a variable that contains a string.
Other helpful methods include .lower() and .upper(). These methods will return a new version of the string it was used on, this time in all lowercase or all uppercase, respectively.
Movie Night
Function Name: movieNight()
Parameters: a caption ( str )
Returns: the fixed caption ( str )
Description: After a long day of classes, you and your friends decide to get together for a movie night. You stream the movie from a very legitimate source, but you run into a problem: the movie captions contain random numbers! Write a function that takes in a caption ( str ) and returns the fixed caption without any numbers.
>>> caption = "Mr. and M4rs. Dursley of nu28mber four, Privet Drive, wer903e proud to say th6at they we6re perfectly norm3al, tha894nk you ve89ry much."
>>> movieNight(caption)
'Mr. and Mrs. Dursley of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much.'
Ice Cream
Function Name: iceCream()
Parameters: flavor ( str ), number of vowels ( int )
Returns: a sentence ( str )
Description: After a couple of movies, you and your friends start craving ice cream. Unfortunately, you are really picky and can only have flavors that contain a certain number of vowels. Write a function that takes in a flavor ( str ) and a number of vowels ( int ), and returns a sentence that indicates whether you can eat this flavor or not. If the ice cream flavor has more vowels than the number passed in, return a string in the following format:
Otherwise, return a string in the following format:
Note: The flavor in the returned string should be converted to all lowercase.
Note: The vowels are any characters in "aeiou"
Dream Car
Function Name: dreamCar()
Parameters: car price ( float ), bank balance( float ), interest rate ( float )
Returns: number of years ( int )
Description: While you're eating your ice cream, you start thinking about your dream car. You want to figure out how long it will take for you to save up and buy that car. Luckily, you've got some money in the bank that's growing every year with compound interest. Given the price of your dream car ( float ), the money you currently have in the bank ( float ), and the interest rate of your bank account ( float ) given as a percent, return how many years it will take for you to have enough money for your dream car.
Note: All parameters will be positive numbers.
Battleship
Function Name: battleship()
Parameters: board size ( int )
Returns: None ( NoneType )
Description: After realizing how long it will take you to buy your dream car, you decide to play a game of Battleship to pass the time. In Battleship, each space on the board is a coordinate, marked with a letter and a number. The letter starts from 'a', and the number starts from '1'. When given a board size, generate a Battleship board for you and your friends to play on. You should only print the board. You will not be given a board size greater than 26.
Tennis Match
Function: tennisMatch()
Parameters: player 1 ( str ), player 2 ( str ), match record ( str )
Returns: winner ( str )
Description: After Battleship, you decide to finish the day by playing tennis with your friends. Each tennis match consists of several games. To keep track, you record the match in a string. In the string, each game is separated by a dash: - . Each game will contain 1s and 2s, where a 1 represents a point scored by player 1, and a 2 represents a point scored by player 2. Whoever has the most points in a game wins that game. If they have the same number of points, that game is not counted. There can be any number of games, and any number of points per game. Return a string containing the winner and the score in the following format:
Grading Rubric
Function Points
movieNight() 15
iceCream() 20
dreamCar() 20
battleship() 20
tennisMatch() 25
Total 100
Provided
The HW03.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