aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2025-06-15 23:11:30 +1000
committerSimon Green <mail@simon.green>2025-06-15 23:11:30 +1000
commit158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6 (patch)
tree76ad90cfc94f4850120bdfd018e6bf01c57609b0 /challenge-325/sgreen/python/ch-2.py
parente28477d2418099cfbb1a227133c69ddef6eed741 (diff)
downloadperlweeklychallenge-club-158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6.tar.gz
perlweeklychallenge-club-158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6.tar.bz2
perlweeklychallenge-club-158ff2b9bb014bcd116bbb9e7bc3fb1ab413f3c6.zip
sgreen solutions to challenge 325
Diffstat (limited to 'challenge-325/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-325/sgreen/python/ch-2.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-325/sgreen/python/ch-2.py b/challenge-325/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..5110b21fa8
--- /dev/null
+++ b/challenge-325/sgreen/python/ch-2.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def final_price(prices: list) -> list:
+ """
+ Function to calculate the final price of items after applying discounts.
+ :param prices: List of integers representing item prices
+ :return: List of final prices after discounts
+ """
+ solution = []
+ for i in range(len(prices)):
+ discount = 0
+ for j in range(i + 1, len(prices)):
+ if prices[j] <= prices[i]:
+ discount = prices[j]
+ break
+ solution.append(prices[i] - discount)
+
+ return solution
+
+
+def main():
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ result = final_price(array)
+ print(result)
+
+
+if __name__ == '__main__':
+ main()