-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18th.py
More file actions
26 lines (22 loc) · 784 Bytes
/
18th.py
File metadata and controls
26 lines (22 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import random
import csv
# Generate sales data for 12 months
months = range(1, 13)
product_names = ["Product A", "Product B", "Product C", "Chair", "Table"]
sales_data = []
for month in months:
row = {"Month": month}
for product in product_names:
row[product] = random.randint(10, 100)
sales_data.append(row)
# Calculate profit as a random percentage of total revenue
for row in sales_data:
revenue = sum(row[product] for product in product_names)
profit = revenue * random.uniform(0.05, 0.20)
row["Profit"] = profit
# Write the data to a CSV file
with open("sales_data.csv", "w", newline="") as f:
writer = csv.DictWriter(
f, fieldnames=["Month"] + product_names + ["Profit"])
writer.writeheader()
writer.writerows(sales_data)