new and playing around to learn.
i want to use one attribute as a complement and automation of another attribute
class ShopItem:
def __init__(self, name='<unnamed>', price=000.00, utility=0, description="<undefined>"):
self.name = name
self.price = price
self.utility = utility
self.description = description
apple = ShopItem("Apple",
1.2,
2,
f"A delicious apple.nRestores {self.utility} hp")
The Last Line
wanted the self.description
to have utility
inside
print(apple.description)
to print:
“Restores 2 hp”
i’ve tried:
...{utility}...
...{self.utility}...
...{apple.utility}...
...{ShopItem.utility}...
the IDE says
... line 12, in <module>
f"A delicious apple.nRestores {self.utility}")
^^^^
NameError: name 'self' is not defined
the not defined
changes to whatever is before the dot
New contributor
user24751274 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.