diff options
Diffstat (limited to 'challenge-325/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-325/eric-cheung/python/ch-2.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-325/eric-cheung/python/ch-2.py b/challenge-325/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..997d8bbb8a --- /dev/null +++ b/challenge-325/eric-cheung/python/ch-2.py @@ -0,0 +1,18 @@ +
+## Ref.:
+## https://www.tutorialspoint.com/program-to-find-final-prices-with-a-special-discount-in-a-shop-in-python
+
+## arrPrice = [8, 4, 6, 2, 3] ## Example 1
+## arrPrice = [1, 2, 3, 4, 5] ## Example 2
+arrPrice = [7, 1, 1, 5] ## Example 3
+
+arrOutput = []
+
+for nIndx, nPrice in enumerate(arrPrice):
+ arrDiscount = [arrPrice[nSubIndxLoop] for nSubIndxLoop in range(nIndx + 1, len(arrPrice)) if arrPrice[nSubIndxLoop] <= nPrice]
+
+ nDiscount = (0 if len(arrDiscount) == 0 else arrDiscount[0])
+
+ arrOutput.append(nPrice - nDiscount)
+
+print (arrOutput)
|
