-
Notifications
You must be signed in to change notification settings - Fork 940
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
Solution #801
base: master
Are you sure you want to change the base?
Solution #801
Conversation
There was a problem hiding this 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! 🎉 The structure and use of functions are well done, and the type annotations are correctly applied. While there are some minor improvements suggested, such as using loops for DRY compliance and checking for key existence to avoid errors, these do not critically impact the functionality. Keep up the good work and consider these suggestions for future enhancements! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -0,0 +1,23 @@ | |||
def apply_armour(knight_data: dict) -> dict: | |||
knight_data["protection"] = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider initializing 'protection' only if it doesn't already exist in 'knight_data'. This will prevent overwriting existing protection values if the function is called multiple times.
|
||
|
||
def apply_weapon(knight_data: dict) -> dict: | ||
knight_data["power"] += knight_data["weapon"]["power"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that 'weapon' and 'power' keys exist in 'knight_data' before accessing them to avoid potential KeyError exceptions.
knight_stats = ["power", "hp", "protection"] | ||
for stat in knight_stats: | ||
if stat in knight_data["potion"]["effect"]: | ||
knight_data[stat] += knight_data["potion"]["effect"][stat] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice to check if 'potion' and 'effect' keys exist in 'knight_data' before accessing them to prevent KeyError exceptions.
@@ -0,0 +1,16 @@ | |||
from app.knight.creation import Knight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement should use double quotes for consistency with the code style guide. Change from app.knight.creation import Knight
to from app.knight.creation import "Knight"
.
from app.knight.creation import Knight | ||
|
||
|
||
def check_hp(knights: list[Knight]) -> list[Knight]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function check_hp
is correctly defined with type annotations. Ensure that the list of knights is passed correctly when calling this function.
"armour": [], | ||
"weapon": { | ||
"name": "Metal Sword", | ||
"power": 50, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing commas are generally discouraged in JSON-like structures. Consider removing the trailing comma after the 'power' key.
], | ||
"weapon": { | ||
"name": "Two-handed Sword", | ||
"power": 55, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing commas are generally discouraged in JSON-like structures. Consider removing the trailing comma after the 'power' key.
], | ||
"weapon": { | ||
"name": "Poisoned Sword", | ||
"power": 60, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing commas are generally discouraged in JSON-like structures. Consider removing the trailing comma after the 'power' key.
"name": "Blessing", | ||
"effect": { | ||
"hp": +10, | ||
"power": +5, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing commas are generally discouraged in JSON-like structures. Consider removing the trailing comma after the 'power' key.
get_damage(knights["lancelot"], knights["mordred"]) | ||
get_damage(knights["arthur"], knights["red_knight"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a loop to iterate over pairs of knights to apply the get_damage
function. This will help adhere to the DRY principle by avoiding repetitive code.
No description provided.