from faker import Faker
import random
fake = Faker()
def generate_product():
categories = ["Electronics", "Clothing", "Home & Garden", "Books", "Toys"]
return {
"id": fake.uuid4(),
"name": fake.catch_phrase(),
"category": random.choice(categories),
"price": round(random.uniform(10, 1000), 2),
"description": fake.paragraph(),
"manufacturer": fake.company(),
"in_stock": random.randint(0, 100),
"rating": round(random.uniform(1, 5), 1),
"features": [fake.bs() for _ in range(3)],
"dimensions": {
"length": round(random.uniform(1, 100), 2),
"width": round(random.uniform(1, 100), 2),
"height": round(random.uniform(1, 100), 2),
"weight": round(random.uniform(0.1, 50), 2)
}
}
# Generate 10 products
product_catalog = [generate_product() for _ in range(10)]
# Print the generated catalog
for product in product_catalog:
print(f"Product: {product['name']}")
print(f"Category: {product['category']}")
print(f"Price: ${product['price']}")
print(f"Description: {product['description']}")
print(f"In Stock: {product['in_stock']}")
print(f"Rating: {product['rating']} / 5")
print("---")
Click Run or press shift + ENTER to run code