Untitled

 avatar
unknown
plain_text
a year ago
1.4 kB
6
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

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'];
            if item['name'] in buyableSnack:
              buyableSnack[item['name']] += 1;
            else:
              buyableSnack[item['name']] = 1;

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



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