You need to press A store has different categories of products in stock shown below TCS Code

A store has different categories of products in stock as shown below.


Item Number=[101, 102, 103, 108]
Item Name=[Milk, Cheese , Ghee, Bread]
Price=[42, 50, 500, 40]
Stock =[10, 20, 15, 16]

When user give input with 2 values as

Item number for item which user wish to buy
Quantity for the item entered above
When user enters above input, the code should check the stock

If quantity is less than stock and item is available display a notification message showing Output Line1 [prices] INR Calculate total price in float with precision. Output Line2 quantity LEFT // updated stock for item after after purchase
2.If the quantity and stocks less than quantity entered by the user while placing order, then display message
Output Line1 NO STOCK

Output Line2 quantity LEFT

3.If user enter character as input for item number and quantity or enter item number which is not available then display following message and stop Output Line1- INVALID INPUT Make sure the string message displayed in output.

Sample INPUT :-

101
4

Sample OUTPUT:-

168.0 INR
6 LEFT

Sample INPUT :-

104
20

Sample OUTPUT:-

NO STOCK
16 LEFT


Solution in Python



Item_Number = [101,102,103,104]
Item_Name = ['Milk', 'Cheese', 'Ghee', 'Bread']
Price = [42,50,500,40]
Stock = [10,20,15,16]

item=int(input("Enter the item number :"))
quant=int(input("Enter the quantity :"))

if item in Item_Number:
    item_index=Item_Number.index(item)
    if quant<=Stock[item_index]:
        print(f"{float(quant*Price[item_index])} INR")
        Stock[item_index]=Stock[item_index]-quant
        print(f"{Stock[item_index]} LEFT")
        
    else:
            print("NO STOCK")
            print(f"{Stock[item_index]} LEFT")
            
else:
                print("INVALId ITEM")

Additional Reading

you can read more articles like this here.

READ MORE

Leave a Reply