function - Error instantiating a class in Python -
i'm attempting instantiate class:
class customer(object): def __init__(self, name, money, ownership): self.name = name self.money = money self.ownership = ownership def can_afford(self): x = false bike in bikes.values(): if self.money >= bike.money * margin: print "customer {} can afford {}".format(self.name, bike) x = true if not x: print "customer {} cannot afford bikes @ time.".format(self.name) shoppers = { # initial condition of shopper1 "jane": customer("jane", 200, false), # initial condition of shopper2 "alfred": customer("alfred", 500, false), # initial condition of shopper3 "taylor": customer("taylor", 1000, false) } buyer = customer(name, money, ownership)
but buyer = customer(name, money, ownership)
keeps getting errored:
undefined variable 'name' undefined variable 'money' undefined variable 'ownership'
but thought set variable's values in dictionary "customer(...)"
class customer(object): def __init__(self, name, money, ownership): self.name = name self.money = money self.ownership = ownership def can_afford(self): x = false bike in bikes.values(): if self.money >= bike.money * margin: print "customer {} can afford {}".format(self.name, bike) x = true if not x: print "customer {} cannot afford bikes @ time.".format(self.name) shoppers = { # initial condition of shopper1 "jane": customer("jane", 200, false), # initial condition of shopper2 "alfred": customer("alfred", 500, false), # initial condition of shopper3 "taylor": customer("taylor", 1000, false) } #this solution mentioned problem name = 'buddy' money = 2 ownership = 'something' buyer = customer(name, money, ownership)
solution mentioned problem above, need define values. there other issues well, bikes.values(), came?
remember, use something, have first tell is, define things.
hope helps.
Comments
Post a Comment