Untitled

 avatar
unknown
plain_text
a year ago
1.2 kB
4
Indexable
# 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
from collections import Counter
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 = [];

convert = Counter()

for item in snacks:
    while amount >= item['price']:
        amount -= item['price']
        convert[item['name']] += 1

print(convert)
Editor is loading...
Leave a Comment