A 1-dimensional array, products, stores the names of available products to be sent to good children all over the world:
| playhouse | teddy | barbie | tank | ... | bike | |
| index | 0 | 1 | 2 | 3 | ... | 99 |
This is a global array in a computer program.
The program needs a function, isAvailable(), which:
Implement this function. Use comments to state the datatype of any variable your solution uses.
Here is a program to help you test your solution:
products = ["playhouse", "teddy", "barbie", "water pistol", "car", "tricycle", "mp3 player", "playstation", "robot", "rabbit"]
#call the function and store the returned data
result = isAvailable()
if result == True:
print("Item available!")
else:
print("Item unavailable")
The 1-dimensional array, products, has been updated. Each element ends with a 3 character number indicating the amount of products in stock. eg:
| playhouse-010 | teddy-178 | barbie-002 | tank-453 | ... | bike-771 | |
| index | 0 | 1 | 2 | 3 | ... | 99 |
The program needs a function, outOfStock(), which:
Implement this function. Use comments to state the datatype of any variable your solution uses.
Here is a program to help you test your solution:
products = ["playhouse-101", "teddy-078", "barbie-012", "water pistol-566", "car-000", "tricycle-000", "mp3 player-000", "playstation-786", "robot-098", "rabbit-000"]
#call the function and store the returned data
result = outOfStock()
print(f"There are {result} products out of stock!")
Implement a new function called outOfStockList()
This function will return an array of items that are out of stock.
For example, for the array in Task 2, if we call outOfStockList() and print the returned array, it will display:
["car-000", "tricycle-000", "mp3 player-000","rabbit-000"]
Each element of the array is added to a file, productData.txt, as a new line.
Jingle bells
Jingle bells
Jingle all the way
Oh what fun
It is to ride
On a one-horse
Open sleigh!