1
1
Fork 0
PythonLearning/online_store/main.py
SeaswimmerTheFsh d9b6631b6f
All checks were successful
Actions / Lint Code (Ruff & Pylint) (push) Successful in 11s
pylint fix
2024-04-29 19:20:40 -04:00

52 lines
2.5 KiB
Python

prices_dict = {
"grapes": 200,
"oranges": 400,
"apples": 600
}
def get_discounted_prices(*prices: int) -> float:
# make a set from the passed arguments to avoid duplicates
prices_set = set(prices)
# if there's still more than three values in the set, raise an error
if len(prices_set) > 3:
raise ValueError("This function only takes up to three arguments.")
# add the prices together
price_sum = sum(prices)
# https://seafsh.cc/u/HR0thZ.png
# apply discounts for the sum
if len(prices_set) == 3:
return float(price_sum * 0.75)
if len(prices_set) == 2:
return float(price_sum * 0.9)
return float(price_sum)
def print_row(item: str, price: str, bold: bool = False) -> None:
# ANSI color codes
blue = "\033[34m" # Blue
green = "\033[32m" # Green
bold_s = "\033[1m" if bold is True else "" # Bold, use an empty string instead of None, because None will be converted to a string by print()
reset = "\033[0m" # Reset to default color
# apply ansi styling for bold, then blue, then offset the first string by 25 characters to the left.
# reset formatting, then do the same thing for the second string but with green as the
# ansi color code instead of blue and offsetting to the right
print(f" {bold_s}{blue}{item:<25}{reset} {bold_s}{green}{price:>25}{reset}")
if __name__ == '__main__':
print("Online Store")
print("⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯")
print_row("Products", "Price", True)
print_row("Grapes", get_discounted_prices(prices_dict["grapes"]))
print_row("Orange", get_discounted_prices(prices_dict["oranges"]))
print_row("Apple", get_discounted_prices(prices_dict["apples"]))
print_row("Grapes & Oranges Combo", get_discounted_prices(prices_dict["grapes"], prices_dict["oranges"]))
print_row("Oranges & Apples Combo", get_discounted_prices(prices_dict["oranges"], prices_dict["apples"]))
print_row("Grapes & Apples Combo", get_discounted_prices(prices_dict["grapes"], prices_dict["apples"]))
print_row("Fruit Gift Pack", get_discounted_prices(prices_dict["grapes"], prices_dict["apples"], prices_dict["oranges"]))
print("⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯")
print("For delivery Contact: (987) 646-78899") # lol?