Gix

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

class GIX:

def __init__(self):

self.farmers = {}

self.buyers = {}

self.crops = {}

def add_farmer(self, name, crop):

self.farmers[name] = crop

def add_buyer(self, name, crop):

self.buyers[name] = crop

def add_crop(self, name, quantity):

self.crops[name] = quantity

def transaction(self, farmer_name, buyer_name, crop_name, quantity):

if farmer_name in self.farmers and self.farmers[farmer_name] == crop_name and buyer_name in


self.buyers and self.buyers[buyer_name] == crop_name and crop_name in self.crops and
self.crops[crop_name] >= quantity:

self.crops[crop_name] -= quantity

print(f"Transaction successful: {farmer_name} sold {quantity} {crop_name} to {buyer_name}.")

else:

print("Transaction failed: either the farmer or buyer doesn't exist, the crop doesn't match, or the
quantity exceeds the available quantity.")

gix = GIX()

gix.add_farmer("Farmer 1", "Crop 1")

gix.add_farmer("Farmer 2", "Crop 2")


gix.add_buyer("Buyer 1", "Crop 1")

gix.add_buyer("Buyer 2", "Crop 2")

gix.add_crop("Crop 1", 100)

gix.add_crop("Crop 2", 150)

gix.transaction("Farmer 1", "Buyer 1", "Crop 1", 50)

gix.transaction("Farmer 2", "Buyer 2", "Crop 2", 75)

You might also like