# Shopping cart It is a partial implementation of a shopping till system, which you might find at a supermarket. This implementation was done by a Junior developer, you as a Senior Software Engineer have been requested to refactor this project. You may make any technical decisions you would like, but must not change the given abstract class (abc.ShoppingCart) which is used by the shopping till hardware and cannot be easily updated. Please treat this code as an element of a larger production system. The code is being refactored to ensure reliability and testability. Tasks requested: - Make the receipt print items in the order that they were added - Add a 'Total' line to the receipt. This should be the full price we should charge the customer - Be able to fetch product prices from an external source (json file, database ...) - Be able to display the product prices in different currencies (not only Euro). - Update the test suite to extend coverage and limit the number of tests which need changing when changes are introduced - Any other changes which improve the reliability of this code in production If you do not have enough information, make any assumptions you would like and note them down with TODO comments. Feel free to make comments that highlight completion of the tasks listed above. Please budget 3 hours to complete. We understand you may have other commitments and time constraints and do evaluate responses with the stated level of effort in mind. Please let me know (roughly) when we should expect your answers or if you need more time. We strive to respond to your effort as promptly as we can. Please don’t forget, your code should be production ready, clean and tested! import abc import typing class ShoppingCart(abc.ABC): @abc.abstractmethod def add_item(self, product_code: str, quantity: int): pass @abc.abstractmethod def print_receipt(self) -> typing.List[str]: pass import typing from . import abc class ShoppingCart(abc.ShoppingCart): def __init__(self): self._items = dict() def add_item(self, product_code: str, quantity: int): if product_code not in self._items: self._items[product_code] = quantity else: q = self._items[product_code] self._items[product_code] = q + quantity def print_receipt(self) -> typing.List[str]: lines = [] for item in self._items.items(): price = self._get_product_price(item[0]) * item[1] price_string = "€%.2f" % price lines.append(item[0] + " - " + str(item[1]) + ' - ' + price_string) return lines def _get_product_price(self, product_code: str) -> float: price = 0.0 if product_code == 'apple': price = 1.0 elif product_code == 'banana': price = 1.1 elif product_code == 'kiwi': price = 3.0 return price def test_add_item(): cart = ShoppingCart() cart.add_item("apple", 1) receipt = cart.print_receipt() assert receipt[0] == "apple - 1 - €1.00" def test_add_item_with_multiple_quantity(): cart = ShoppingCart() cart.add_item("apple", 2) receipt = cart.print_receipt() assert receipt[0] == "apple - 2 - €2.00" def test_add_different_items(): cart = ShoppingCart() cart.add_item("banana", 1) cart.add_item("kiwi", 1) receipt = cart.print_receipt() assert receipt[0] == "banana - 1 - €1.10" assert receipt[1] == "kiwi - 1 - €3.00"
Desarrollador De Software Python Interview Questions
5,401 desarrollador de software python interview questions shared by candidates
How a backend server works
What is the use of python. What are the libraries in python
Why do you want to work in a startup compared to a bigger corporation?
1. Self Introduction 2. Basic Python Questions like which is list and array. 3. Dictionary Based Questions like how to sort dict by keys. 4. Insight of projects you have done
None specified in the round
The First round consists of 3 Easy level programming questions
Given a linked list with the first 100 fibonacci numbers, reverse it.
All of them were unintelligible.
write a program for factorial, about academic project, basic programming questions
Viewing 3671 - 3680 interview questions
See Interview Questions for Similar Jobs
Desarrollador PythonDesarrollador De Python SeniorDesarrollador Net JuniorDesarrollador De Software GraduadoDesarrollador De DjangopythonIngeniero De Software PhpDesarrollador De Software CDesarrollador De Software IDesarrollador DotnetIngeniero De Software Ruby On Rails Desarrollador Ruby On RailsIngeniero De Software De GráficosDesarrollador De Software PhpDesarrollador C .net JuniorDesarrollador De Software JavaDesarrollador Python JuniorDesarrollador CProgramador Python