aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/sgreen/python/ch-2.py
blob: 5110b21fa8a0761cdcc55bb84d4c777890048864 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()