Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solutions #1265

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

This-is-Lapwing
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on your code so far! However, there's a small issue with the hook_load method in the DeliveryDrone class. It's critical to ensure that the drone doesn't carry more weight than it's supposed to. I believe you can fix this with a minor adjustment. Keep up the good work! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

app/main.py Outdated
Comment on lines 49 to 58
def hook_load(self, cargo: Cargo) -> None:
if self.current_load is None and cargo.weight <= self.max_load_weight:
self.current_load = cargo
print(f"Hooked load of weight {cargo.weight}"
f". Current load: {self.current_load.weight}")
elif (isinstance(self.current_load, Cargo) and self.current_load.weight
+ cargo.weight <= self.max_load_weight):
self.current_load.weight += cargo.weight
print(f"Hooked load of weight {cargo.weight}"
f". Current load: {self.current_load.weight}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook_load method seems to have some issues. In the case where there is no current load, it correctly checks that the weight of the cargo to be hooked is less than or equal to the maximum load weight. However, in the case where there is a current load, it only checks that the weight of the current load plus the weight of the cargo to be hooked is less than or equal to the maximum load weight. This could lead to a situation where the drone is carrying more weight than it is supposed to. It would be better to check that the weight of the cargo to be hooked is less than or equal to the maximum load weight minus the weight of the current load.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on the code, but there's still room for improvement. Remember to handle edge cases in your methods and avoid using mutable default arguments as they can lead to unexpected behavior. Also, consider using exceptions instead of print statements for error handling. Keep up the good work! 👍

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +6 to +10
class BaseRobot:
def __init__(self, name: str, weight: int, coords: list = None) -> None:
self.name = name
self.weight = weight
self.coords = coords if coords is not None else [0, 0]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'coords' attribute is a mutable default argument. It's a common Python pitfall. If a new instance of BaseRobot (or any class that inherits from it) is created without providing a 'coords' value, they will all share the same list. It's better to use a non-mutable default value like None and create a new list in the constructor.

Comment on lines +49 to +62
def hook_load(self, cargo: Cargo) -> None:
current_load_weight = \
(self.current_load.weight) if self.current_load else 0
available_capacity = self.max_load_weight - current_load_weight

if cargo.weight <= available_capacity:
if self.current_load:
self.current_load.weight += cargo.weight
else:
self.current_load = cargo
print(f"Hooked load of weight {cargo.weight}"
f". Current load: {self.current_load.weight}")
else:
print("Cannot hook load. Exceeds max load weight.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook_load method could be improved. Right now, if the drone already has a load, it increases the weight of the current load. It might be better to keep a list of loads, so that you can track individual cargo items. Also, using print statements for error handling is not a good practice. Consider raising exceptions instead.

Comment on lines +64 to +66
def unhook_load(self) -> None:
self.current_load = None
print("Load unhooked. Current load is now None.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unhook_load method sets the current load to None without any checks. What if there is no load to begin with? It would be better to first check if there is a load to unhook and handle the situation appropriately.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on writing the code! However, there are a few areas that need your attention for improvement. The unhook_load function should check if there's a load to unhook before setting self.current_load to None. In hook_load, consider raising an exception when the cargo weight exceeds capacity. Also, avoid using mutable default arguments to prevent unexpected behavior. Keep up the good work, and remember, every mistake is a learning opportunity! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +6 to +10
class BaseRobot:
def __init__(self, name: str, weight: int, coords: list = None) -> None:
self.name = name
self.weight = weight
self.coords = coords if coords is not None else [0, 0]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the coords parameter, you are using a mutable default argument (a list) which can lead to unexpected behavior. It's a common Python pitfall. When the default mutable argument is modified, the modification is permanent, thus the default argument is not so default after the first modification. A better approach would be to make the default value None and then assign the default value in the body of the function if None is provided.

Comment on lines +49 to +62
def hook_load(self, cargo: Cargo) -> None:
current_load_weight = \
(self.current_load.weight) if self.current_load else 0
available_capacity = self.max_load_weight - current_load_weight

if cargo.weight <= available_capacity:
if self.current_load:
self.current_load.weight += cargo.weight
else:
self.current_load = cargo
print(f"Hooked load of weight {cargo.weight}"
f". Current load: {self.current_load.weight}")
else:
print("Cannot hook load. Exceeds max load weight.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook_load function could be improved. Currently, when the cargo weight exceeds the available capacity, the function simply prints a message and exits. It would be more robust to raise an exception in this case. This would allow the calling code to catch the exception and handle it appropriately, rather than having to check the console output to see if the function succeeded.

Comment on lines +64 to +66
def unhook_load(self) -> None:
self.current_load = None
print("Load unhooked. Current load is now None.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unhook_load function sets self.current_load to None without checking if there is a load to unhook. This could potentially lead to unexpected behavior. It would be safer to first check if self.current_load is not None, and only then set it to None and print a message. If self.current_load is already None, you could print a different message or raise an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants