Created
December 13, 2022 22:52
-
-
Save samirsaci/cbd129fd60d17292e6ff8754d21b56bc to your computer and use it in GitHub Desktop.
Digital Twin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a Truck class to represent a truck | |
class Truck: | |
def __init__(self, location, capacity): | |
self.location = location | |
self.capacity = capacity | |
self.cargo = {} | |
def load_cargo(self, item, quantity): | |
if sum(self.cargo.values()) + quantity <= self.capacity: | |
if item in self.cargo: | |
self.cargo[item] += quantity | |
else: | |
self.cargo[item] = quantity | |
else: | |
print("Error: Not enough capacity to load cargo.") | |
def unload_cargo(self, item, quantity): | |
if item in self.cargo and self.cargo[item] >= quantity: | |
self.cargo[item] -= quantity | |
else: | |
print("Error: Cargo not found.") | |
def move_to(self, location): | |
self.location = location | |
# Create a truck at location "Paris" with a capacity of 100 | |
truck = Truck("Paris", 100) | |
# Load 50 units of item "A" onto the truck | |
truck.load_cargo("A", 50) | |
# Move the truck to location "Lille" | |
truck.move_to("Lille") | |
# Unload 25 units of item "A" from the truck | |
truck.unload_cargo("A", 25) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment