diff options
Diffstat (limited to 'challenge-325/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-325/sgreen/python/ch-2.py | 32 |
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() |
