Question: Write a class House defined as follows: A constructor that takes three arguments: an integer p, an integer s, and a string c. The

Write a class House defined as follows: A constructor that takes three arguments: an integer p, an integer s, and a string c. The values of those three local variables must be assigned to three attributes: self.price, self.sqft, and self.city. A method_str_ that returns a string with the three attribute values, each on a new line. A method unitPrice that returns the price per square feet (obtained by dividing self.price by self.sqft), rounded as an integer. Outside (and after) the block of code defining the class House, write the fol- lowing tests: Create an object h1 by calling the constructor of the class House with the three argument values 240000, 1400, and "Philadelphia'. Print h1. Print hl.unitPrice (). You must obtain the following result: 240000 1400 Philadelphia Create a second object h2 by calling the constructor of the class House with the three argument values 160000, 1000, and 'New York. Create a dictionary dico. Add hi at the key 'Paul' and h2 at the key 'Mary'. Print the data stored at the key "Mary' 3. Write a function displayUnit that takes as an argament a dictionary d where the keys are first names (strings) and the value at each key is an object of the class House defined in Question 2. The function must print each key followed by the price per square feet of the house at this key, each on a new line. The call of this function with the dictionary dico created in Question 2. displayUnit (dico) must give the following result, exactly: Unit price of Paul's house: 171 Unit price of Mary's house: 160
Step by Step Solution
3.49 Rating (159 Votes )
There are 3 Steps involved in it
class House def initself p s c Constructor that takes two integers p and s and a string c and initia... View full answer
Get step-by-step solutions from verified subject matter experts
