class Package:
def __init__(self, name, weight):
self.name = name
self.weight = weight
class Truck:
def __init__(self, max_weight=1000):
self.max_weight = max_weight
self.current_weight = 0
self.packages = []
def load(self, package):
if self.current_weight + package.weight > self.max_weight:
print(f"적재 용량 초과({self.current_weight + package.weight}/{self.max_weight}). 해당 물품은 다음 트럭으로 이월됩니다.")
return False
self.packages.append(package)
self.current_weight += package.weight
return True
trucks = []
trucks.append(Truck())
package1 = Package("박스1", 950)
package2 = Package("박스2", 60)
trucks[-1].load(package1)
if not trucks[-1].load(package2):
trucks.append(Truck())
trucks[-1].load(package2)
To embed this project on your website, copy the following code and paste it into your website's HTML: