English, asked by nitinsinghb552, 2 days ago

.A store has different categories of products in stock as shown below. Item Number= (101, 102, 103, 104] Item Name= [Milk, Cheese, Ghee, Bread] Price= [42, 50, 500, 40) Stock= [10, 20, 15, 16) When user give input with 2 values as - 1. Item number for item which user wish to buy 2. Quantity for the item entered above When user enters above in​

Answers

Answered by satyam21461
8

Language used: Python Programming

Program:

#defining lists

ItemNumber= [101, 102, 103, 104]

Item Name= [Milk, Cheese, Ghee, Bread]

Price= [42, 50, 500, 40]

Stock= [10, 20, 15, 16]

#Taking the inputs

itemnum = input()

quantity = input()

#checking if no characters are inputted and if the itemnumber entered is present in the given list or not

if itemnum.isnumeric() and quantity.isnumeric() and (itemnum in ItemNumber):

  itemnum=int(itemnum)

  quantity=int(quantity)

  #taking the index of the itemnumber for further usage

  for i in range(len(ItemNumber)):

      if itemnum == ItemNumber[i]:

          indexx=i

          break

  #Print the bill, if the asked quantity is available in the stock; update the stock and print the stock left.

  if (quantity<=Stock[indexx]):

      print("{:.1f} INR".format(quantity*Price[indexx]))

      Stock=Stock[indexx]-quantity

      print("{0} LEFT".format(Stock[indexx]))

  #Print the NO STOCK left message if the quantity asked is greater than the stock available and print the stock in availability.

  elif quantity>Stock[indexx]:

      print("NO STOCK")

      print("{0} LEFT".format(Stock[indexx]))

#When the invalid value is inputted by the user

else:

  print("INVALID INPUT")

Similar questions