COMP 141: Project 4

Polly's Pawfully Purrfect Pets

Polly runs a pet-sitting business called Polly's Pawfully Purrfect Pets. People hire her to take care of their dogs and cats while they are out of town. In this program, you will use functions and loops to calculate information about Polly's prices for the pet-sitting itself, and for the cost of food.

Pet Sitting Prices

For each customer, Polly calculates their daily rate based on the number of dogs and cats the customer owns, the distance she has to drive to get to the customer's house, and the level of care the customer chooses.

Polly offers three levels of service: basic, pro, and supreme. For dogs, basic care is $12/day, pro care is $15/day, and supreme care is $19/day. For cats, the rates are the same, except $1 less per day. These rates are per-pet, so for two dogs, double the dog rate, and so on, for multiple dogs and/or cats. (Polly does offer discounts for multiple pets, described below.)

Polly has to drive to each customer's house, so she adds an extra fee onto her daily rates if she has to drive a long distance. If the customer lives more than two miles away, she adds one dollar per mile (over two) to the daily rate. So if a customer lives 1 or 2 miles away, there is no extra fee; for three miles, add $1/day; for four miles, add $2/day, and so on.

Polly offers discounts for taking care of multiple pets. The discount is applied after multiplying her base rates by the number of dogs and cats she's caring for. (For instance, the base rate for taking care of 2 dogs and 2 cats for a customer who lives 5 miles away who chooses the "basic" level of care is: 2 * $12 (for the dogs) + 2 * $11 (for the cats) + $3 (for the extra driving) = $24 + $22 + $3 = $49/day.) If Polly cares for one pet, there is no discount. For taking care of two pets (any combination of dogs and cats), she takes 15% off the total daily rate. For three pets, she takes 25% off, and for four or more pets, she takes off 35%.

Once Polly determines the base rate, she multiplies the base rate by the number of days she's caring for the pets to get the total price. If she's taking care of the pets for a week (7 days) or more, then she applies one last 10% discount to the total price.

Food prices

Among other things, Polly takes care of feeding the pets while the customer is away. She pays for the food herself, so she wants to compute its cost ahead of time. For dogs, she can buy large bags of food for $13 each that feed one dog for one week (7 days), or small individual bags of food that feed one dog for one day for $2 each. For dogs, she can buy large bags of food for $10 each that feed one cat for one week (7 days), or small individual cans of food that feed one cat for one day for $1.50 each.

What you need to do

Step 0: Refresh your memory on commenting your code

This is the first time you'll be using function you write yourself, so make sure you understand how to comment on them before the "def" line for each function.

Step 0.5: Copy the starter Python code below into a new file

Step 1: Write the following functions

You must write the following functions. After writing each function, test them from the Python shell. You do this by running the program (press F5 or choose Run -> Run Module) and calling the function from the Python shell with different arguments and seeing if you get the right answers. Once you have written these functions, tested them, and they all work, you can move on to Step 2, which is writing the main function.

Step 2: Write main()

Write a main function to do the following:

Step 3: Add a loop to main

Add a while loop to your main function so that after the total cost of food is printed, the user is asked if they want to calculate the costs for a different pet sitting situation. If they answer yes, they can do it again, otherwise the program ends.

Start with this code

You should use the following program structure: (Yes, literally copy it into a blank Python program)
# Name: 
# Date: 
# Class: 
# Project: 
# Pledge: 
# Description: 

# This function calculates the day of the year for the "zero-th" day of each month.
# month: the number of the month from 1-12.
# returns: the day of the year
def day_of_year_for_month(month):
    if month == 1:
        return 0
    elif month == 2:
        return 31
    elif month == 3:
        return 31 + 28
    elif month == 4:
        return 31 + 28 + 31
    elif month == 5:
        return 31 + 28 + 31 + 30
    elif month == 6:
        return 31 + 28 + 31 + 30 + 31
    elif month == 7:
        return 31 + 28 + 31 + 30 + 31 + 30
    elif month == 8:
        return 31 + 28 + 31 + 30 + 31 + 30 + 31
    elif month == 9:
        return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31
    elif month == 10:
        return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30
    elif month == 11:
        return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31
    elif month == 12:
        return 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
           
# This function calculates the day of the year for any day of each month.
# month: the number of the month from 1-12.
# date: the day of the month from 1-31.
# returns: the day of the year
def day_of_year(month, date):
    return day_of_year_for_month(month) + date

Example run

What month are you leaving? 4
What day of the month are you leaving? 5
What month are you returning? 4
What day of the month are you returning? 6
You will be gone for 1 days.

How many dogs do you own? 1
How many cats do you own? 1
How many miles will the sitter have to travel? 4
The basic level will cost you:   21.25
The pro level will cost you:     26.349999999999998
The supreme level will cost you: 33.15

Dog food will cost you:          2
Cat food will cost you:          1.5
Total cost of food is:           3.5

Do you want to calculate costs for another situation? yes


What month are you leaving? 6
What day of the month are you leaving? 7
What month are you returning? 7
What day of the month are you returning? 15
You will be gone for 38 days.

How many dogs do you own? 2
How many cats do you own? 3
How many miles will the sitter have to travel? 5
The basic level will cost you:   1333.8
The pro level will cost you:     1667.25
The supreme level will cost you: 2111.85

Dog food will cost you:          142
Cat food will cost you:          163.0
Total cost of food is:           305.0
Do you want to calculate costs for another situation? no
Thanks for using the calculator!

Submission