Professional Documents
Culture Documents
Electron Is
Electron Is
Electron Is
If you want to use encapsulation and make the attributes private by adding
double underscores (`__`) after `self`, you can do so. Here's the corrected code
with encapsulation:
```python
class Room:
def __init__(self, number, floor):
self.__number = number # Private attribute
self.__floor = floor # Private attribute
def access_room_number(self):
return self.__number
def access_room_floor(self):
return self.__floor
In this version, `__number` and `__floor` are private attributes, and they can only
be accessed within the `Room` class. The methods `access_room_number` and
`access_room_floor` provide controlled access to these private attributes. This
way, you achieve encapsulation, which helps in protecting the internal state of the
`Room` object.