- Import the required libraries:
import datetime
import random
- Define the function to calculate the total cost:
def calculate_total_cost(items):
total_cost = 0
for item in items:
total_cost += item['price'] * item['quantity']
return total_cost
- Define the function to display the receipt:
def display_receipt(items):
print("----- Receipt -----")
for item in items:
print(f"{item['name']}: ${item['price']} x {item['quantity']} = ${item['price'] * item['quantity']}")
print("-------------------")
- Define the main billing system function:
def customer_billing_system():
items = []
while True:
name = input("Enter item name (or 'q' to quit): ")
if name == 'q':
break
price = float(input("Enter item price: "))
quantity = int(input("Enter item quantity: "))
items.append({'name': name, 'price': price, 'quantity': quantity})
total_cost = calculate_total_cost(items)
display_receipt(items)
# Generate a random customer reference number
reference_number = random.randint(1000, 9999)
print(f"Total Cost: ${total_cost}")
print(f"Reference Number: {reference_number}")
confirmation = input("Confirm the billing (y/n): ")
if confirmation.lower() == 'y':
print("Billing confirmed. Thank you!")
else:
print("Billing canceled.")
- Call the main billing system function:
customer_billing_system()
This code allows you to enter item details (name, price, and quantity) in a loop until you choose to quit by entering ‘q’. It calculates the total cost of the items, displays a receipt with itemized costs, generates a random customer reference number, and asks for confirmation before finalizing the billing.
Please note that this is a basic example and may require further enhancements, such as error handling and data validation, depending on your specific requirements.