Question
As a Real Estate Tycoon you are planning to purchase properties in different blocks around the city. However, there is a maximum number of properties
As a Real Estate Tycoon you are planning to purchase properties in different blocks around the city. However, there is a maximum number of properties you can buy based on your budget. Write a function mass purchase() that takes arguments in the following order: city: A list of lists of integers representing prices of properties. Each integer represents the price of a building in millions of dollars ($M). budget: An integer that represents the maximum amount in dollars (in $M) you can spend on purchasing bulidings. The function iterates over the list of lists, visiting the values in this order: city[0][0], city[0][1], city[0][2], ..., city[1][0], city[1][1], city[1][2], ... Note that it is not necessarily the case that every row (e.g., city[i]) has the same number of properties. As the function visits each integer value, it adds the value to a running total, provided that doing so would not cause the total to exceed the budget. Adding an integer to the total therefore corresponds with purchasing a building. Each time a building is purchased, the indexes of that building in the list are appended to a list (lets call it result). For example, suppose that the function decides to purchase the buildings city[0,2], city[1,0] and city[3,7]. The return value of the function (result) would be the list of lists [[0,2], [1,0], [3,7]]. Important: the buildings that are purchased must be added in the order specified in the previous paragraph. Hint: use nested for-loops, where the outer loop iterates over the list city and the inner loop iterates over a sub-list of city (e.g., a particular city[i]). Part of the code you will need to write is given below: result = [] for i in ________ : for j in ________ : if ________ : result.append([i, j])
Examples: Function Call mass-purchase ([[12], [2, 1, 6, 7, 14, 11], [1, 3, 4],[[O, 0, [1, 0], [8, 9, 1, [5, 13, 4]1, 46) Return Value [2, 0, [2, 11 mass-purchase ([[13, 10, 5, 9, 14], [14, 11, 11, 8], [13, 9], [12, 11, 13, 9], [12, 7, 6, 7, 3, 6], 33) mass-purchase ([[12, 7, 9, 14, 11], [6, 8, 7, 6, 2, 5], [4, 13], [6, 7, 12, 6, 11, 2], [12, 7, 14, 3, 2,[0, 2], [0, 31] 3], [14, 13, 7, 2, 7, 8], [13, 7], 42) mass-purchase ([[2, 11, 9, 7, 9], [14, 4, 2, 4], [7, 14, 6, 12], [7, 5, 13], [3, 3, 1, 9, 9], [12, 3, 2, 2], [11, 7, 14], [9, 7], [14, 5]], 46) mass purchase ([[1, 12, 9], [12, 6, 7, 6], [6], 48) mass-purchase ([14, 14, 2], [6], [6, 11, 7, 9, 9, [7, 12, 14, 4, 14], [8, 13]], 41) 13, 311 mass-purchase ([[4, 7, 7, 1, 7], [8, 11, 4, 1], [10, 1, 9, 14, 3], [9, 12, 5], [9, 10, 13, 6], [14, 1, 6, [0, 2, [0, 3], 14, 4], [13, 12], 36) mass-purchase ([[12, 11], [3, 8, 8, 11, 8, 7], 23) mass.purchase ([[8, 6, 11], [12, 8], [5, 2, 9, 6, 14],[0, 0], [0, 1], [6, 12], [1, 2, 10, 12, 12, 13]], 48) [4, 011 mass-purchase ([[9, 10], [13], [8, 10], [2, 10, 12, 13], [12, 12, 2, 5, 9, 31, [5, 2, 4]], 36) [4, 211Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started