Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- transactions = [
- {'id': 1, 'product': 'apple', 'quantity': 3, 'price': 1.25},
- {'id': 2, 'product': 'banana', 'quantity': 2, 'price': 0.75},
- {'id': 3, 'product': 'apple', 'quantity': 1, 'price': 1.25},
- {'id': 4, 'product': 'orange', 'quantity': 4, 'price': 1},
- {'id': 5, 'product': 'banana', 'quantity': 2, 'price': 0.75},
- {'id': 6, 'product': 'orange', 'quantity': 1, 'price': 1},
- {'id': 7, 'product': 'orange', 'quantity': 2, 'price': 1},
- {'id': 8, 'product': 'orange', 'quantity': 3, 'price': 1},
- {'id': 9, 'product': 'dalandan', 'quantity': 3, 'price': 3},
- {'id': 10, 'product': 'dalandan', 'quantity': 2, 'price': 3},
- ]
- def generate_report(transactions):
- product_revenue = dict()
- total = 0
- for i in range(len(transactions)):
- quantity = transactions[i][list(transactions[i])[2]]
- price = transactions[i][list(transactions[i])[3]]
- product = transactions[i][list(transactions[i])[1]]
- if product in product_revenue:
- product_revenue[product] = product_revenue[product] + quantity * price
- else:
- product_revenue[product] = quantity * price
- total = total + (quantity * price)
- for i, j in product_revenue.items():
- print(f"{i} : {j}")
- print("Total :", total)
- generate_report(transactions)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement