Having a string representing items in a cart, elaborate taxes and totals. Interview task in Python A couple of weeks ago I had to do a coding challenge for a job interview. I did the challenge using Python, the code was working and I got the job. But I would like to know how (if possible) I can improve/refactor the code I've written.
The reviewer told my future employer there were too many if statements and that I could have written better code.
I guess this is an example of too many if statements:
def get_row_tax_percentage(product_name: str):
    exempt = is_exempt(product_name)
    imported = is_imported(product_name)
    if exempt and imported:
        return Decimal(&quot;.05&quot;)
    elif exempt and not imported:
        return Decimal(&quot;0&quot;)
    elif imported:
        return Decimal(&quot;.15&quot;)
    else:
        return Decimal(&quot;.1&quot;)

Link to the task description: https://github.com/xpeppers/sales-taxes-problem
Link to my solution: https://github.com/soulpaul/sales-taxes-solution
I think this could be a chance to learn something new. I don't need you guys to write code for me, but please point me to the right direction.
Thanks to anyone who is going to spend some time on this.
That really depends on how the task is stated. If it's stated like your code, just in English, with four different (and possibly independent) values, then I'd say your way is actually ok. Because then if one of them changes, you only need to change the value, not rewrite logic.
But the task description says:

Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions.

So it is in fact stated as two separate taxes that should be determined separately and just added. Make the code's logic reflect the real logic.
For extra clarity, use the proper names as well. For example:
def get_row_tax_percentage(product_name: str):
    basic_sales_tax = 10 if not is_exempt(product_name) else 0
    import_duty = 5 if is_imported(product_name) else 0
    return Decimal(basic_sales_tax + import_duty) / 100

Or maybe with 0 if is_exempt(product_name) else 10, I can't decide which I find clearer and/or closer to how the task says it.