Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Write a class named House that has the following data attributes: __year_built (for the year the house was built) __sqr_ft (for the square footage

Question:

Write a class named House that has the following data attributes:

__year_built (for the year the house was built)

__sqr_ft (for the square footage of the house)

__num_beds (for the number of bedrooms)

The House class should have an __init__ method that accepts the year the house was built and the square footage as arguments. These values should be assigned to the objects __year_built and __sqr_ft data attributes. It should also assign 1 to the __num_beds data attribute.

The class should also have the following methods:

add_bed

The add_bed method should add 1 to the __num_beds data attribute each time it is called.

addition

The addition method should add 100 to the sqr_ft data attribute each time it is called.

get_beds

The get_beds method should return the current number of bedrooms.

get_sqr_ft

The get_sqr_ft method should return the current square footage of the house.

Next, design a program that creates a House object and then calls the add_bed method five times. After each call to the add_bed method, get the number of bedrooms in the house and display it. Then call the addition method five times. After each call to the addition method, get the current square footage of the house and display it.

I have the below code but am getting an error when trying to run it:

class House: def __init__(self,year,sqr): self.__year_built=year self.__sqr_ft=sqr self.__num_beds=1

def add_bed(self): self.__num_beds+=1

def addition(self): self.__sqr_ft+=100

def get_beds(self): return self.__num_beds

def get_sqr_ft(self): return self.__sqr_ft

houseObj=House(2023,1500)

print("At starting Number of beds are",houseObj.get_beds()) print("At starting the current square footage of the house",houseObj.get_sqr_ft())

print(" Calling add_bed() method five times ")

for i in range(5): houseObj.add_bed() print("Number of beds are",houseObj.get_beds())

print(" Calling addition() method five times ")

for i in range(5): houseObj.addition() print("The current square footage of the house",houseObj.get_sqr_ft())

image text in transcribed

print("At starting Number of beds are", houseobj.get_beds ()) ttributeError: 'House' object has no attribute 'get_beds

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

9. Describe the characteristics of power.

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago