Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
3
Indexable
Never
# Yudi went to indomaret, he has 30.000 to spent for snacks
# There are list of snacks
# Pringles has the price Rp.15000
# Potabee has the price Rp.10000
# JetZ has the price Rp.6000
# Nyam-nyam has the price Rp.4000
# Beng-beng the price Rp.3500
# Taro has the price Rp.3000
# Cheetos has the price Rp.2000
# Chiki balls has the price Rp.1500
# In order yudi to spend his money efficiently to buy as many different products as possible and do the priority based on the expensive one first

amount = input("Please input amount of money: ")
amount = int(amount)

snacks = [{'name': 'Pringles', 'price': 15000},
          {'name': 'Potabee', 'price': 10000},
          {'name': 'JetZ', 'price': 6000},
          {'name': 'Nyam-nyam', 'price': 4000},
          {'name': 'Beng-beng', 'price': 3500},
          {'name': 'Taro', 'price': 3000},
          {'name': 'Cheetos', 'price': 2000},
          {'name': 'Chiki', 'price': 1500} ]


def get_price(element):
    return element['price']


snacks.sort(key=get_price, reverse=True)
buyableSnack = [];

while (amount > get_price(snacks[-1])):
    for item in snacks:
        if amount >= item['price']:
            amount = amount - item['price'];
            buyableSnack.append(item['name']);

print("List of buyed products: \n")

convert = {}

for item in buyableSnack:
    if item in convert:
        convert[item] += 1
    else:
        convert[item] = 1

print(convert)
Leave a Comment