CS1301 Homework 1 - Functions and Expressions Solution
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 functions and evaluate expressions. The homework will consist of 5 functions for you to implement. You have been given HW01.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 Enrique Bercian (qbercian@gatech.edu) & Parul Srivastava (psrivastava61@gatech.edu) Helpful Information To Know
String Formatting A concept that will be very helpful for this homework is string formatting. String formatting allows you to manipulate strings using variables so that string values can change based on whatever information is stored in the variables. To explore this concept, letʼs look at an example where a user inputs a name and age, and the code prints out the corresponding information: name = input("What is your name?") age = input("How old are you?") print("Your name is {} and you are {} years old!".format(name, age))
Rounding Numbers Python has a built-in function that allows you to round numbers. For example:
Listen Function Name: listen() Parameters: N/A Returns: None
Domino's Time Function Name: dominosTime() Parameters: N/A Returns: None Description: During the summer, you ordered a lot of food from Domino's. Pizzas are $12, an order of pasta is $6, and chicken wings are $8. Write a function that asks the user how many of each food item they would like, and then print a response telling them what their order total will be. The order total should be an integer.
Tip and Split Function Name: tipAndSplit() Parameters: N/A Returns: None Description: You are hanging out with your friends at home and decide to order some food. The delivery man was really nice, and you want to tip him. Additionally, you want to split the total between your friends after adding the tip to the total. Write a function that takes as an input the order total, the percentage you want to tip the driver, and the number of friends that are splitting the food. Print the tip and how much each friend must pay. All inputs will be positive integers. Round all outputs to 2 decimal places.
YouTuber Function Name: youtuber() Parameters: N/A Returns: None Description: You are quarantined and you are bored, so you decide to become a YouTuber. You become successful, and are getting paid from ads. You decide to set up a function that calculates how much money you have made. Write a function that takes as an input the number of videos you have made, how many views each video has, and the amount you are getting paid per view. We assume that every video has the same amount of views. Print how much money you have earned. Round your answer to 2 decimal places.
Bath Bomb Function Name: bathBomb() Parameters: N/A Returns: None Description: In order to relax before your classes pick up, you decided to take a bath. Before dropping the bath bomb, you decided to measure the volume of it. Write a function that asks the user what the radius of the bath bomb is, and then calculate the volume of the sphere with the given dimensions. The radius can be a float. Round your answer to 2 decimal points.
Grading Rubric
Function Points listen() 20 dominosTime() 20 tipAndSplit() 20 youtuber() 20 bathBomb() 20 Total 100 Provided The HW01.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