2024-05-08 12:43:05 -04:00
from typing import Any , Literal , Union
prices_dict : dict [ str , int ] = {
2024-04-29 18:46:36 -04:00
" 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 )
2024-04-29 19:20:40 -04:00
if len ( prices_set ) == 2 :
2024-04-29 18:46:36 -04:00
return float ( price_sum * 0.9 )
2024-04-29 19:20:03 -04:00
return float ( price_sum )
2024-04-29 18:46:36 -04:00
2024-05-08 12:43:05 -04:00
def print_row ( item : str , price : Union [ str , Any ] , bold : bool = False ) - > None :
2024-04-29 18:46:36 -04:00
# ANSI color codes
blue = " \033 [34m " # Blue
green = " \033 [32m " # Green
2024-05-08 12:43:05 -04:00
bold_s : Literal [ ' \u001b [1m ' ] | Literal [ ' ' ] = " \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()
2024-04-29 18:46:36 -04:00
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 ( " ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ " )
2024-04-29 19:20:03 -04:00
print ( " For delivery Contact: (987) 646-78899 " ) # lol?