0% found this document useful (0 votes)
14 views2 pages

Sodapdf

This Python code processes transactions for vegetable purchases from multiple clients. It initializes variables to track total clients, highest amount paid, and lowest amount paid. It defines functions to calculate totals for individual products, subtotals before/after taxes, and final totals accounting for discounts. The main loop greets each client, gets their vegetable purchases, calculates various totals, prints a bill, and updates the tracking variables. At the end it prints a summary of totals processed, highest amount, and lowest amount.

Uploaded by

kunkunn0021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Sodapdf

This Python code processes transactions for vegetable purchases from multiple clients. It initializes variables to track total clients, highest amount paid, and lowest amount paid. It defines functions to calculate totals for individual products, subtotals before/after taxes, and final totals accounting for discounts. The main loop greets each client, gets their vegetable purchases, calculates various totals, prints a bill, and updates the tracking variables. At the end it prints a summary of totals processed, highest amount, and lowest amount.

Uploaded by

kunkunn0021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import datetime

# Initialize variables
TotalClients = 0
HighestAmount = 0
LowestAmount = float(’inf’)

# Function to calculate product line total


def calculate_product_line_total(quantity, price_per_kg):
return quantity * price_per_kg

# Function to calculate total before taxes


def calculate_total_before_taxes(*totals):
return sum(totals)

# Function to calculate total after VAT


def calculate_total_after_vat(total_before_taxes):
vat_rate = 0.09
return total_before_taxes * (1 + vat_rate)

# Function to calculate total to be paid after deduction for lucky clients


def calculate_total_to_be_paid(total_before_taxes, is_lucky_client):
deduction_rate = 0.17
if is_lucky_client:
return total_before_taxes * (1 - deduction_rate)
else:
return total_before_taxes

# Main loop for processing transactions


while True:
# Greet the client
ClientFN = input("Enter client’s full name (or ’q’ to quit): ")
if ClientFN.lower() == ’q’:
break

TotalClients += 1 # Increment the total number of clients processed

# Display available vegetables and their prices


vegetables = {"Tomatoes": 12, "Potatoes": 15, "Carrots": 19, "Celery": 21, "Onions": 25}
print("\nAvailable Vegetables:")
for veg, price in vegetables.items():
print(f"{veg}: {price} DH per Kg")

# Get the name and quantity of 3 vegetables


V1 = input("Enter the name of the first vegetable: ")
V1Q = float(input(f"Enter the quantity of {V1} in Kg: "))
V2 = input("Enter the name of the second vegetable: ")
V2Q = float(input(f"Enter the quantity of {V2} in Kg: "))
V3 = input("Enter the name of the third vegetable: ")
V3Q = float(input(f"Enter the quantity of {V3} in Kg: "))

# Calculate product line totals


TotalL = calculate_product_line_total(V1Q, vegetables.get(V1, 0)) + \
calculate_product_line_total(V2Q, vegetables.get(V2, 0)) + \
calculate_product_line_total(V3Q, vegetables.get(V3, 0))
# Calculate total before taxes
TotalBT = calculate_total_before_taxes(TotalL)

# Calculate total after VAT


TotalAT = calculate_total_after_vat(TotalBT)

# Check if the client is lucky based on family name


is_lucky_client = ClientFN.upper()[0] in [’A’, ’B’, ’C’, ’D’, ’E’, ’F’]

# Calculate total to be paid after deduction for lucky clients


TotalTbP = calculate_total_to_be_paid(TotalBT, is_lucky_client)

# Display the bill


print("\n------ Bill ------")
print(f"Client: {ClientFN}")
print(f"Date: {datetime.datetime.now().strftime(’%Y-%m-%d %H:%M:%S’)}")
print("\nVegetable\tQuantity\tPrice\t\tTotal")
print(f"{V1}\t\t{V1Q}\t\t{vegetables.get(V1, 0)}\t\t{calculate_product_line_total(V1Q, vegetables.get(V1,
0))}")
print(f"{V2}\t\t{V2Q}\t\t{vegetables.get(V2, 0)}\t\t{calculate_product_line_total(V2Q, vegetables.get(V2,
0))}")
print(f"{V3}\t\t{V3Q}\t\t{vegetables.get(V3, 0)}\t\t{calculate_product_line_total(V3Q, vegetables.get(V3,
0))}")
print("\nTotal before taxes: {:.2f} DH".format(TotalBT))
print("Total after VAT: {:.2f} DH".format(TotalAT))
print("Total to be paid: {:.2f} DH".format(TotalTbP))

# Update highest and lowest amounts paid


if TotalTbP > HighestAmount:
HighestAmount = TotalTbP
if TotalTbP < LowestAmount:
LowestAmount = TotalTbP

# Display end-of-day summary


print("\n------ End of Day Summary ------")
print(f"Number of clients processed: {TotalClients}")
print(f"Highest amount paid: {HighestAmount:.2f} DH")
print(f"Lowest amount paid: {LowestAmount:.2f} DH")

You might also like