I am having a file discount.txt that contain data in following format:
Less than $100 --> 0%
From $100 up to less than $500 --> 10%
From $500 up to less than $1,000 --> $40 PLUS 20%
From $1,000 up to less than $2,000 --> $140 PLUS 30%
$2,000 and above --> $440 PLUS 40%
It means Discount on the sale amount
Less than $100 0%
From $100 up to less than $500 10% for each dollar over $100
From $500 up to less than $1,000 $40 PLUS 20% of the total sale amount over $500
From $1,000 up to less than $2,000 $140 PLUS 30% of the total sale amount over $1,000
$2,000 and above $440 PLUS 40% of the total sale amount over $2,000
That is, if the total sale amount is $100 then the discount will be $0. However, if the total sale amount is $101 then the discount will be $0.10. If the total sale amount is $500 then the discount will be $40, but if the total sale amount is $501 then the discount will be $40.20.
So to solve this , what I think is to have 4 lists : 1 list for storing lower limit of sale amount, one for upper limit, one for holding fixed increment corresponding to a range and one for holding additional discount. If there is no fixed increment then assume it zero.
Then for given sales amount if it lies in ith range then just do something like :
fixedIncrement[i] + (saleAmount-lowerLimit[i])*additionDiscount[i]
But problem am facing is parsing the given text file. Can someone please help to parse it and store it in lists in python
Here in given file the lists would be something like this :
lowerLimit[] = [1,100,500,1000,2000]
upperLimit[] = [100,500,1000,2000,MAX]
fixedIncrement[] = [0,0,40,140,440]
additionDiscount[] = [0,0.1,0.2,0.3,0.4]