Sunday, May 16, 2021

Calculating total price in a text list of items

 So I have this list of stuff I want to buy:

> Latest total, correct?

> laser guns 100, magnetic wall calendar 150, 2 trays 20, twin sheets 40, blue twin sheets 30, boots 50, 3 pot set 200, electric kettle 200, toaster 50, blue Pyrex 100, set of 3 food storage containers 75, salad spinner 40, PC Batter bowl with lid 100, white/flower serving dish 30, cast iron skillet 80, microwave 400, pizza pans 50, splatter guard 20, muffin pan 40, file box 100, cooling rack 40, blue table cloth 50, basting brush 20, tongs 10, meat scissors 40, ice cream scoop 30, potato masher 30, pastry blender 20, meat tenderizer 10, 2 large knives 80 lei, spatula 10, Zester 10, meat thermometer 10, Black File folder 10, black knife/sharpener 20, all metal hangers 100, 3 kitchen items 110, children’s hangers 20, total - 2585.

How to verify without manually adding? Using VS code and Python:


Press "Replace all", and you get: "100,150,20,40,30,50,200,200,50,100,75,40,100,30,80,400,50,20,40,100,40,50,20,10,40,30,30,20,10,10,10,10,10,20,100,110,20,".

Then

$ python

>>> sum([100,150,20,40,30,50,200,200,50,100,75,40,100,30,80,400,50,20,40,100,40,50,20,10,40,30,30,20,10,10,10,10,10,20,100,110,20,])

2415

>>>

No comments:

Post a Comment