Answer to Question #349239 in Python for kaavya

Question #349239

Implement the following problem statement in python along with test cases. Let’s say you have a Customer class and you want to test calculate bill method of customer class. Bill calculation will depend on list of items customer purchased


1
Expert's answer
2022-06-08T17:23:53-0400
class Customer:
    def bill(self, items: list) -> float:
        # This variant of the prices is presented only as an example
        # For a larger number of items it should be imported
        price = {"Book1": 12.97,
                 "Book2": 87.36,
                 "Book3": 10.73}
        total = 0.0
        for item in items:
            total += price.get(item)
        return round(total, 2)
    pass

# TEST PART

test_customer = Customer()

test_items_1 = ["Book1"]
test_items_2 = ["Book2", "Book3"]
test_items_3 = ["Book1", "Book3", "Book2", "Book2"]

total_cost_1 = Customer.bill(test_customer, test_items_1)
total_cost_2 = Customer.bill(test_customer, test_items_2)
total_cost_3 = Customer.bill(test_customer, test_items_3)

print(f"Total cost of all items from {test_items_1} is {total_cost_1}")  
print(f"Total cost of all items from {test_items_2} is {total_cost_2}")
print(f"Total cost of all items from {test_items_3} is {total_cost_3}")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS