Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added homework9/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions homework9/homework9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from collections import namedtuple


CAPACITY = 400
items = []

Item = namedtuple('Item', 'name weight value')
with open('items.txt', 'r') as f:
for data in f.readlines():
name, weight, value = data.strip().split(sep=',')
items.append(Item(name, int(weight), int(value)))

load = 0
for item in sorted(items, key=lambda x: x.weight / x.value):
if load + item.weight > CAPACITY:
break
print('{}: weight={}, value={}'.format(item.name, item.weight, item.value))
load += item.weight
22 changes: 22 additions & 0 deletions homework9/items.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
map,9,150
compass,13,35
water,153,200
sandwich,50,160
glucose,15,60
tin,68,45
banana,27,60
apple,39,40
cheese,23,30
beer,52,10
suntan cream,11,70
camera,32,30
T-shirt,24,15
trousers,48,10
umbrella,73,40
waterproof trousers,42,70
waterproof overclothes,43,75
note-case,22,80
sunglasses,7,20
towel,18,12
socks,4,50
book,30,10
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from distutils.core import setup


setup(
name='Homework_9',
version='0.1',
description='Homework 9 for Advanced Python course',
author='Yury Kliachko',
author_email='yury_kliachko@epam.com',
url='http://www.epam.com',
packages=['homework9']
)