Answer to Question #239717 in Python for addie

Question #239717
Given a shopkeeper in your location is in need of an accounting system which will ensure
efficient recording and easy report generation of every day transactions. Using the classes,
control structures, appropriate types and other program constructs write a python program which:
a) Captures products in stock (i.e. name, price, date supplied, supplier name, quantity).
b) Retrieves the price when name is given upon each purchase and deducts the quantity in
stock.
c) Calculates the total price for each purchase and prints value indicating date and time of
purchase.
d) Sends an alert when quantity reaches 5 to shopkeeper and places order to supplier.
1
Expert's answer
2021-09-20T16:43:28-0400
import datetime
class Stock:
    def __init__(self, name, price, supplier, quantity,date):
        self.name = name
        self.price = price
        self.date = date
        self.supplier = supplier
        self. quantity = quantity

    def check_item(self, name):
        for i in range(len(ls)):
            if (ls[i].name == name):
                return i

    def sale(self):
        n = int(input("How many products to sale: "))
        total = 0
        for j in range(n):
            name = input("Enter Product name : ")
            quantity = int(input("Enter quantity: "))
            i = obj.check_item(name)
            if i and ls[i].quantity >= quantity:
                ls[i].quantity -= quantity
                if ls[i].quantity < 5:
                    print("Low Stock! Low Stock! Order Placed")
                    obj.place_order(name, ls[i].supplier, quantity+10)
                print("....Uncle G Shop....")
                print(datetime.date.today())
                print("Product Name  | Quantity  | Cost $")
                print(ls[i].name, end=" ")
                print(quantity, end=" ")
                print(ls[i].price * quantity)
                total += ls[i].price * quantity
                print("\n")
                print("Total Cost----->", "$" + total)
            else:
                print("Product out of stock or not enough quantity")


    def purchase(self):
        name = input("Enter Product name: ")
        date = datetime.date.today()
        i = obj.check_item(name)
        if i:
            ls[i].quantity += int(input("Enter quantity: "))
            ls[i].price = int(input("Enter product price: "))
            ls[i].date = date
        else:
            quantity = int(input("Enter quantity: "))
            price = int(input("Enter product price: "))
            supplier = input("Enter Supplier: ")
            ob = Stock(name, price, supplier, quantity, date)
            ls.append(ob)


    def place_order(self,name, supplier, quantity):
        return name, supplier, quantity

    def print_products(self):
        def __repr__(self):
            return str(self.name) + str(self.price) + str(supplier) + str(self.quantity) + str(self.date)
        return __repr__

    def main(self):
        print("Welcome To Uncle G Shop")
        print("choose an option below")
        print("\n1.Enter a Product\n2.Make a sale \n3.See all Products\n4.Exit")
        option = int(input("Enter option here: "))
        while True:
                

            if option == 1:
                obj.purchase()
            elif option == 2:
                obj.sale()
            elif option == 3:
                obj.print_products()
            elif option == 4:
                print("Have a good day")
                break
            else:
                print("Enter a valid input!")
# A list to add Products
ls = []

# an object of Stock class
obj = Stock('', 0, 0, 0, '')
obj.main()

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