BYU logo Computer Science

To start this assignment, download this zip file.

The following guide pages cover material needed for this assignment:

Lab 3f — Structured Data

Preparation

1 minute

Download the zip file for this lab, located above. This zip file has code that you will use for this assignment. Extract the files and put them in your cs110 directory in a folder called lab3f.

Yelp

15 minutes

You are provided with starter code (yelp.py) for an app that queries the user for a list of restaurants and ratings and then identifies which restaurant to go to.

Discussion

Notice the structure of the app: the main function breaks the problem down into three steps:

  • Get the ratings
  • Find the highest-rated restaurant
  • Print the result

What kind of data does pick_highest(ratings) expect? Is it a string? And integer? A list? A list of what?

What kind of data should get_ratings() return? From the code we can see it returns a list, but a list of what?

What should get_rating_info() return? How should it create that information?

Implement

Now implement get_rating_info and pick_highest. Look at the examples in the guide if you need inspiration: Lists of tuples

Testing

Run your app. Test it with different restaurant names and scores.

You should be able to see something like this:

Restaurant: Supreme Burger
Rating: 5
Restaurant: Wendy's
Rating: 3.5
Restaurant: Costa Vida
Rating: 4.5
Restaurant: 
Supreme Burger is rated 5.0 stars.

Highest Predicted Return on Investment

20 minutes

A house flipper is deciding which house to buy, fix, and sell. Help them find the house that will yield the most profit.

The user will enter houses like this:

Address: 123 800 S Provo
Purchase price: 82000
After repair value: 98000
Cost to repair: 10000
Project duration: 1

Address: 321 400 N Orem
Purchase price: 112000
After repair value: 140000
Cost to repair: 15000
Project duration: 6

Address:

This is the function to calculate the expected profit.

def get_profit(house: tuple) -> float:
    address, purchase_price, after_repair_value, cost_to_repair, project_duration = house
    monthly_property_taxes = purchase_price / 1000
    cost_of_sale = 3000
    costs = purchase_price + cost_to_repair
    costs += monthly_property_taxes * project_duration
    costs += cost_of_sale
    return after_repair_value - costs

Select the house that will return the most profit, and display it like this:

Expected profit: $9328.0

Address: 321 400 N Orem
Purchase price: $112000.0
After repair value: $140000.0
Cost to repair: $15000.0
Project duration: 6.0 months

Tips

  • Describe the inputs and outputs of each function
  • What functions should main call? What functions should be called by those functions?
  • When finding the “best” house, how will you use the get_profit function?
    • You’ll want to keep track of the max_profit so far, and update it when you find a house with better profit.
    • Use a similar pattern to what you used in yelp.py

Maximizing Monthly Income

5 minutes

Modify the previous code so that you return the highest profit per month. The highets profit per month can be calculated like this: profit_per_month = profit / project_duration.

Make a new function, called profit_per_month(), that uses the get_profit() function you already created.

Change the program to print the house with the highest profit per month:

Expected profit per month: $2918.0

Address: Provo
Purchase price: $82000.0
After repair value: $98000.0
Cost to repair: $10000.0
Project duration: 1.0 months

Grading

To finish this lab and receive a grade, take the canvas quiz.

We are providing a solution so you can check your work. Please look at this after you complete the assignment. 😊