# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("10_args_kwargs_q", "week_5", "readings", assignment_points = 30.0, assignment_tag = 'week5-readings')
# Initialize Otter
import otter
grader = otter.Notebook("10_args_kwargs_q.ipynb")
โ *args
and **kwargs
in Brawl Stars#
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_args_kwargs_q import Question1
Question1().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_args_kwargs_q import Question2
Question2().show()
# Run this block of code by pressing Shift + Enter to display the question
from questions._10_args_kwargs_q import Question3
Question3().show()
Question 1 (Points: 7.0): Write a Function to Display Brawler Stats#
Write a Python function named display_brawler_stats
that:
Accepts a brawlerโs name as the first parameter.
Accepts additional statistics as keyword arguments (
**kwargs
).Prints the brawlerโs name and their statistics in the format:
Name: <name> Health: <value> Power: <value>
Use the string method
capitalize()
to capitalize the the stat which you are describing
...
# Example usage
display_brawler_stats("Shelly", health=3600, power=10)
grader.check("Brawler-Stats-question")
Question 2 (Points: 14.0): Brawlerโs Survival Challenge#
In Brawl Stars, characters take damage from enemy attacks and receive healing from allies or abilities. Your task is to implement a system that calculates a brawlerโs remaining hitpoints after taking damage and receiving healing.
Instructions#
You need to implement the following three functions:
apply_damage(hitpoints, damage)
Parameters:
hitpoints
(int): The brawlerโs current HP.damage
(int): The amount of damage taken.
Returns: The new HP after taking damage. If HP falls below zero, it should return zero. This can be done several ways. One way is to use the
max()
function to return the maximum of 0 and the result of the subtraction.
apply_healing(hitpoints, healing, max_hitpoints)
Parameters:
hitpoints
(int): The brawlerโs current HP.healing
(int): The amount of healing received.max_hitpoints
(int): The brawlerโs maximum HP.
Make sure healing does not happen it the Brawler has been eliminated (HP = 0), or if the healing would exceed the maximum HP.
Returns: The new HP after healing, but it cannot exceed
max_hitpoints
. You can use themin()
function to return the minimum ofmax_hitpoints
and the result of the addition.
calculate_remaining_hp(starting_hp, max_hp, damage_taken, healing_received)
Calls the first two functions to compute the final HP of the brawler.
Parameters:
starting_hp
(int): The brawlerโs initial HP.max_hp
(int): The brawlerโs maximum HP.damage_taken
(int): The total damage received.healing_received
(int): The total healing received.
Returns: The final HP after applying damage and healing.
Example Usage#
# Shelly starts with 3600 HP and takes 1200 damage, but receives 500 healing.
remaining_hp = calculate_remaining_hp(3600, 3600, 1200, 500)
print(remaining_hp) # Expected Output: 2900
# Function to apply damage to a brawler's HP
...
# Function to apply healing to a brawler's HP
...
# Function to calculate remaining HP after applying damage and healing
...
grader.check("Brawler-Damage-Stats")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week5-readings", "10_args_kwargs_q")