In: Computer Science
implement the following logic in Python, use appropriate data types. Data types are represented as either numeric (num) or string.
string name
string address
num item
num quantity
num price
num SIZE = 6
num VALID_ITEM [SIZE] = 106, 108, 307, 405, 457, 688
num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00
num sub
string foundIt = “N”
string MSG_YES = “Item available”
string MSG_NO = “Item not found”
get name, address, item, quantity
sub = 0
while sub <= SIZE
if item == VALID_ITEM [sub] then
foundIt = “Y”
price = VALID_ITEM_PRICE [sub]
endif
sub = sub + 1
endwhile
if foundIt == “Y” then
print MSG_YES
print quantity, “ at “ , price, “ each”
print “Total “, quantity * price
else
print MSG_NO
endif
IN PYTHON
#declare valid item list
VALID_ITEM = [106,108,307,405,457,688]
#declare price for item
VALID_ITEM_PRICE = [0.59,0.99,4.50,15.99,17.50,39.00]
#inititalize sub to 0
sub = 0
#inititalize size to 6
SIZE = 6
foundit = 'N'
#takes name from user and store it in name variable
name = input("Enter name: ")
#takes address from user and store it in address variable
address = input("Enter address: ")
#takes item from user and store it in item variable
item = input("Enter item: ")
#takes quantity from user and store it in quantity variable
quantity = input("Enter quantity: ")
#checks if entered item is found in valid item list
#if found then change the value of foundit to Y
# and store the price value for that item in price variable
while (sub < SIZE):
if(int(item) == VALID_ITEM[sub]):
foundit = 'Y'
price = VALID_ITEM_PRICE[sub]
sub = sub+1
#if foundit is Y then Item is availabe
#prints quantity and price for that Item and total price
if(foundit == 'Y'):
print("Item available")
print(quantity ," at ", price, " each ")
print("Total: ", int(quantity) *float(price))
#if foundit is N then item not found in VALID_ITEM list
#prints item not found
else:
print("Item not found")
OUTPUT: