Code Monkey home page Code Monkey logo

samsungentrancetest's Introduction

Samsung Innovation Campus

Выполнения заданий вступительного теста Samsung Innovation Campus

backpack.py - Задание №8

Исходный код:

class Item:
    def __init__(self, name, weight):
        self.name = name
        self.weight = weight


class Main:
    def __init__(self):
        self.items = []

    def add_item(self, item):
        self.items.append(item)

    def find_heaviest_item(self):
        if not self.items:
            return None  # Рюкзак пустой

        heaviest_item = self.items[0]

        for item in self.items:
            if item.weight > heaviest_item.weight:
                heaviest_item = item

        return heaviest_item


if __name__ == "__main__":
    backpack = Main()

    # Добавляем предметы в рюкзак
    backpack.add_item(Item("Меч", 5))
    backpack.add_item(Item("Щит", 7))
    backpack.add_item(Item("Зелье здоровья", 1))

    # Находим самый тяжелый предмет
    heaviest_item = backpack.find_heaviest_item()

    if heaviest_item:
        print("Самый тяжелый предмет в рюкзаке:", heaviest_item.name)
    else:
        print("Рюкзак пустой")

samsungentrancetest's People

Contributors

theaweny avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.