Update page 'Day 5 homework - Sloetjes'

xuanyi.wang
2023-04-07 00:08:09 +02:00
parent 945aa2704f
commit c3a76662e9
+3 -2
@@ -1,6 +1,6 @@
# Xuanyi Wang\_Day-5\_Homework\_04/05/23
The assignment for tonight is to write a class named Vault containing an attribute named "treasure" which returns "gold" under normal circumstances, but a warning message such as "attribute deleted!" if it detects any of its attributes have been changed. You can use the descriptor protocol (__set__, etc) to detect if its attributes have been changed, and it will have to check its own __dict__ against a known good copy before accessing the treasure attribute to make sure that the attributes are what they're supposed to be.
**The assignment for tonight is to write a class named Vault containing an attribute named "treasure" which returns "gold" under normal circumstances, but a warning message such as "attribute deleted!" if it detects any of its attributes have been changed. You can use the descriptor protocol (set, etc) to detect if its attributes have been changed, and it will have to check its own dict against a known good copy before accessing the treasure attribute to make sure that the attributes are what they're supposed to be.**
```
@@ -27,7 +27,8 @@ print(v.treasure) # prints 'gold'
v.x = 10
print(v.treasure) # prints 'Attribute deleted!\ngold'
```
To get the other person's class to return "gold", despite any countermeasures they've implemented:
**To get the other person's class to return "gold", despite any countermeasures they've implemented:**
###### It can be achieved by creating a new class that inherits from the Vault class and overrides its _treasure attribute.
```
class GoldVault(Vault):