File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,3 +111,24 @@ def call_external_api(user_id):
111111
112112fetch_user_data (123 )
113113
114+ # from logger_config
115+
116+ from logger_config import setup_logger
117+
118+ logger = setup_logger (__name__ )
119+
120+ def calculate_discount (price , discount_percent ):
121+ logger .debug (f'Calculating discount: { price } * { discount_percent } %' )
122+
123+ if discount_percent < 0 or discount_percent > 100 :
124+ logger .warning (f'Invalid discount percentage: { discount_percent } ' )
125+ discount_percent = max (0 , min (100 , discount_percent ))
126+
127+ discount = price * (discount_percent / 100 )
128+ final_price = price - discount
129+
130+ logger .info (f'Applied { discount_percent } % discount: ${ price } -> ${ final_price } ' )
131+ return final_price
132+
133+ calculate_discount (100 , 20 )
134+ calculate_discount (100 , 150 )
You can’t perform that action at this time.
0 commit comments