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
- SEO Practices Everyone Should Follow SEO Rules
- Complete Top SEO Checklist
- Yoast Seo Premium 15.2 Nulled – WordPress SEO Plugin
- Top 50+ SEO Interview Questions
- What is a Backlink? How to Get More Backlinks
- TCS INTERVIEW QUESTIONS – CLICKE HERE
- Top 20 Interview Program Questions
- Android Projects with Source Code
- Python Project With Source Code
- Python Projects Ideas
- Machine Learning MCQ Questions
- Highest Paying Earning Website
- School Database Management System
- Top 20 Company Interview Questions