basic price modeling in python
import sys
"""
Prototype for price model automata
"""
class ItemPrice(object):
"""
Object that models item price based on supply and demand
Calculates price by (D/S) * constant
"""
def __init__(self, name, constant, demand=1.0, supply=1.0):
self.name = name
self.constant = constant
self.supply = supply
self.demand = demand
def get_price(self):
if self.supply == 0.0:
return float("inf")
else:
return (self.demand/self.supply) * self.constant
def __repr__(self):
return str((self.name, self.constant, self.demand, self.supply, self.get_price()))
if __name__ == '__main__':
print ItemPrice("apple", 1.5, 15.0, 12.0)
print ItemPrice("pear", 1.6, 15.0, 12.0)