Having some issues with earning money with classes.
Here's the code.
Trying to use the earn to add money and spend it.
Getting "earn money is not defined.". Not quite sure what to do, because it seems to be defined in the class, unless I'm wrong about something. I've looked at a number of tutorials online and they have things set up this way. It's possible that these tutorials are out of date and that's the issue.
Any help would be appreciated.
Thanks!
Here's the code.
Code:
init python:
class Item:
def __init__(self, name, cost):
self.name = name
self.cost = cost
class Inventory:
def __init__(self, money=0):
self.money = money
self.items = []
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
self.items.append(item)
return True
else:
return False
def earn(self, amount):
self.money += amount
def has_item(self, item):
if item in self.items:
return True
else:
return False
Code:
c "Ok. Here's $200. There's a store nearby."
$ earn.money(200)
Any help would be appreciated.
Thanks!