This is a program I wrote in Python for the Computer Science class "Computer Science Fundamentals I" (CS1026) at Western university.
In this program I calculate from a list of widgets if each widget can be built with the parts I have.
First the parts file is read in and processed inputting the name, price and quantity of each part into three lists.
Then it creates a master list (The database) of all the parts and two dictionaries for the price and quantity of each part.
It will next print out the stock of each part before widget processing and open the widgets file and starts processing the file.
When the program gets to a new widget it clears all variables for processing them and reads all the parts needed for that one widget.
Next it checks if the widget can be built with the parts currently in stock.
If widget can be built, the program reduces the related part stocks by the number that was used up.
It also calculates the cost of the widget and then prints out all the information it gathered thus far.
If the widget can't be built it prints out that it can't be built detailing why it can't be built.
After all widgets have been processed it prints out the stock of each part after widget processing.
The program ends by closing the parts and widgets files.