def show_status(self): print("\n" + "="*40) print(f"π° Balance: $self.balance:.2f") print("π¦ Inventory:") for item, qty in self.inventory.items(): print(f" item: qty pcs (current price: $self.prices[item]:.2f)") print("="*40)
def buy(self, item, quantity): if item not in self.prices: print("β Invalid item.") return cost = self.prices[item] * quantity if cost > self.balance: print(f"β Not enough money. Need $cost:.2f, have $self.balance:.2f") return self.balance -= cost self.inventory[item] += quantity print(f"β Bought quantity x item for $cost:.2f")
> sell Rainbow Pop 10 β Sold 10 x Rainbow Pop for $124.50
def get_portfolio_value(self): total = self.balance for item, qty in self.inventory.items(): total += qty * self.prices[item] return total
def suggest_trade(self): """Simple AI suggestion: buy if price is near lowest recorded, sell if near highest""" suggestions = [] for item in self.prices: hist = self.price_history[item] low = min(hist) high = max(hist) current = self.prices[item] if current <= low * 1.05: suggestions.append(f"π BUY signal for item (near low: $current:.2f)") elif current >= high * 0.95: suggestions.append(f"β οΈ SELL signal for item (near high: $current:.2f)") if suggestions: print("\nπ AI Trader Suggestion:") for s in suggestions: print(s) else: print("\nπ€ No strong signals right now. Hold or wait.")
self.price_history = item: [price] for item, price in self.prices.items()