Starting from:

$24.99

CS1301 Homework 1 Solution


2. This homework will be graded out of 100 points: 90 points from your GradeScope grade and 10 points from you adding a picture of yourself to your Canvas profile.
4. For Help:
● How to Think Like a Computer Scientists
● [ http://openbookproject.net/thinkcs/python/english3e / ]
● CS 1301 Python Debugging Guide
● [http://www.cc.gatech.edu/classes/AY2016/cs1301_spring/CS-1301-Deb u gging-Guide/index.html ]

6. Comment out or delete all of your function calls. Only import statements, global variables, and comments are okay to be outside the scope of a function.
7. Read the entire document before starting this assignment.

Introduction


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. Let’s look at an example where a user inputs a name, and the code prints the name out:

name = input("What is your name?") print("Your name is {}".format(name))


Read this for more info: [ https://pyformat.info/ ]

Rounding numbers

Python has a built-in function that allows you to round numbers. For example:

>> rounded_number = round(3.1415926, 4)
>> print(rounded_number)
3.1416

Inside the parentheses of the round() function, put the number you want to round, followed by a comma and the number of decimal places you want to round the number to.


PART 1: FUNCTIONS

Function name: calorie_count()
Parameters: no parameters
Returns: None
Description: It’s the new year, and you want to start counting your calorie intake! Write a function that asks the user how many hamburgers, orders of french fries, and cookies they eat, and how many minutes they have walked. Each hamburger is 400 calories, each order of french fries is 200 calories, and each carrot stick is 25 calories. Every minute the user walks burns 5 calories. Calculate how many calories the user intakes, and print a response in the format shown below. The inputs will be integers.

Test Cases:

>>> calorie_count()
How many hamburgers would you like? 3
How many orders of french fries would you like? 2
How many carrot sticks would you like? 0
How many minutes did you walk? 30
3 hamburgers, 2 orders of french fries, 0 carrot sticks, and 30 minutes walked is 1450 calories.

>>> calorie_count()
How many hamburgers would you like? 6
How many orders of french fries would you like? 1
How many carrot sticks would you like? 10
How many minutes did you walk? 15
6 hamburgers, 1 orders of french fries, 10 carrot sticks, and 15 minutes walked is 2775 calories.


Function name: cone_volume()
Parameters: no parameters
Returns: None
Description: You love ice cream, but as part of your new diet, you have to watch how much you’re eating. You want to know exactly how much ice cream you can fit into an ice cream cone! Write a function that asks the user to input the radius and height of a cone and calculates the cone’s volume using the given dimensions. Print a response in the format shown in the test cases below. The height and radius can be a float.

Note: Use the variable ‘pi’ that is provided . You should round the volume to two decimal places. However, trailing zeros should be like 152.0 instead of 152.00

Hint: The formula for the volume of a cone is: π * r 2 * (h / 3).

Test Cases:

>>> cone_volume()
What is the height of the cone? 10
What is the radius of the cone? 4
The volume of a cone with a height of 10.0 and a radius of 4.0 is 167.55.

>>> cone_volume()
What is the height of the cone? 2.5
What is the radius of the cone? 1.2 The volume of a cone with a height of 2.5 and a radius of 1.2 is 3.77.



Function name: watch_time()
Parameters: no parameters
Returns: None

Test Cases:

>>> watch_time()
How many movies have you watched? 2
How many TV show episodes have you watched? 5
By watching 2 movies and 5 TV show episodes, you have spent 5 hour(s) and 45 minutes on Disney+.

>>> watch_time()
How many movies have you watched? 9
How many TV show episodes have you watched? 15
By watching 9 movies and 15 TV show episodes, you have spent 22 hour(s) and 45 minutes on Disney+.


Function name: liquid_conversion()
Parameters: no parameters
Returns: None
Description: You’re trying to drink more water this year, so you’re keeping track of how many glasses of water you drink in a day. Write a function that asks the user for how many cups of water they drink and then calculates how many gallons, quarts, pints, and cups that number represents. The input will be an integer. Remember that there are 2 cups in a pint, 2 pints in a quart, and 4 quarts in a gallon.

Hint: Use floor division and modulus to help determine the largest unit that can be used to measure the water.

Test Cases:

>>> liquid_conversion()
How many cups of water did you drink? 16 You drank 1 gallon(s), 0 quart(s), 0 pint(s), and 0 cup(s) of water.

>>> liquid_conversion()
How many cups of water did you drink? 3 You drank 0 gallon(s), 0 quart(s), 1 pint(s), and 1 cup(s) of water.

Function name: savings_calculator()
Parameters: no parameters
Returns: None
Description: This year, you’re going to try to save more money! You want to calculate how much money you will have in your savings account after a certain amount of months. Write a function that asks the user to input the principal (the amount originally put into the account), the interest rate as a percentage, and the amount of months that have passed. Calculate how much money will be in the savings account after the time has passed. Print a response like the examples shown below. The principal and interest rate can be floats, while the amount of months will be an integer.

Note: Round to 2 decimal places. However, trailing zeros should be like $1005.0 instead of $1005.00

Hint: The formula for calculating this is P(1 + rt), where P is the principal, r is the interest rate as a decimal , and t is the number of years . This means that you’ll have to convert the interest rate given from a percentage to a decimal and the months given to years.

Test Cases:

>>> savings_calculator()
What is the principal? 1000
What is the interest rate? 2
How many months have passed? 3 You will have $1005.0 at the end of 3 months.

>>> savings_calculator()
What is the principal? 1030.50
What is the interest rate? 15
How many months have passed? 6
You will have $1107.79 at the end of 6 months.

PART 2: Canvas Profile Picture
Set a picture of yourself as your Canvas Profile Picture. Rea d here for information on how to add a Canvas Profile Picture.


Grading Rubric

calorie_count: 15 pts cone_volume: 15 pts watch_time: 20 pts liquid_conversion: 20 pts savings_calculator: 20 pts
Canvas Picture 10 pts
__________________________________________________
Total 100 pts


& S


Provided

The following file(s) have been provided to you.

1. HW01.py
This is the file you will edit and submit to GradeScope. All instructions for what the functions should do are in the docstrings.

Deliverables

1. HW01.py






More products