List function questions
So let’s pretend that I have a program that reads lines from from a txt file and converts them into a list def vendInventory(): Example of line one in txt file : A1 soda $1.50 3 Once it is read and stored as a list within my function it looks like [A1, soda, $1.50, 3] The first 3 elements don’t matter because they will remain the same but the fourth element I need to be an int so that I can subtract the number of items purchased from its inventory when a purchase is made(when I will call the function in my main loop) and then then write it to a temp file and strip it to where it has no commas or brackets for printing In your opinion what would the most efficient way be Let’s pretend you have created the function and you’ve opened the text file in read mode and temp file in write mode you need to read text file then convert it to a list with the first 3 elements being strings and the 4th as an int then you need to subtract the numItems purchased from that int and store it in the temp file then delete the text file and rename the temp file with the name text file using os this way can call your read function to display the vending machine options and use the vendInventory function to subtract from the inventory when items are purchased