Python: Total Damages   Example skill_book = { 'mage': {'punch':10, 'spellcast':50}, 'shielder': {'punch': 5 }, 'vanguard': {'quickpunch':10, 'punch':20, 'kick':30} } assert total_damage(skill_book, [('mage','punch'), ('mage','punch')]) == 20 # each mage's punch deal 10 damage assert total_damage(skill_book, [('mage','punch'), ('vanguard','punch')]) == 30 # each vanguard's punch deal 20 damage, so the total is 10+20 = 30 assert total_damage(skill_book, [('mage','spellcast'), ('vanguard','punch'), ('vanguard','punch')]) == 90 assert total_damage(skill_book, [('vanguard','punch'), ('vanguard','kick'), ('shielder','punch')]) == 55

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter14: Files And Streams
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question
100%

Python: Total Damages

 

Example

skill_book = { 'mage': {'punch':10, 'spellcast':50}, 'shielder': {'punch': 5 }, 'vanguard': {'quickpunch':10, 'punch':20, 'kick':30} }

assert total_damage(skill_book, [('mage','punch'), ('mage','punch')]) == 20 # each mage's punch deal 10 damage

assert total_damage(skill_book, [('mage','punch'), ('vanguard','punch')]) == 30 # each vanguard's punch deal 20 damage, so the total is 10+20 = 30

assert total_damage(skill_book, [('mage','spellcast'), ('vanguard','punch'), ('vanguard','punch')]) == 90

assert total_damage(skill_book, [('vanguard','punch'), ('vanguard','kick'), ('shielder','punch')]) == 55

In an RPG game, you are controlling a team of multiple heroes to fight against monsters. Each hero equips with
various offensive skills each of which deals different amount of damage. The amount of damage for the skills is given
in a dictionary as follows:
{ <hero_A>: { <skill_A1> : <damage_A1>, <skill_A2> : <damage_A2>,
<hero_B>: { <skill_B1> : <damage_B1>, <skill_B2> : <damage_B2>,
},
..
},
}
where <hero_*>'s and <skill_*>'s are strings, and <damage_*>'s are a non-negative integers. For example, if
<hero_A> performs an attack with <skill_A1>, the amount of damage from that attack is <damage_A1>.
The game keeps a combat_log which basically is a list heros' actions. Each action is a tuple (hero_name, skill_name)
which means that hero_name performs skill_name . The total damage is simply the sum of all damages dealt by all
the attacks in the combat log.
Your task is to write a function total_damage(skill_book:dict[str,dict[str,int]], combat_log:list[tuple[str,str]])
-> int that computes the total amount of damage dealt from all actions in the given combat_log according to the
skill_book written in the aforementioned format.
Transcribed Image Text:In an RPG game, you are controlling a team of multiple heroes to fight against monsters. Each hero equips with various offensive skills each of which deals different amount of damage. The amount of damage for the skills is given in a dictionary as follows: { <hero_A>: { <skill_A1> : <damage_A1>, <skill_A2> : <damage_A2>, <hero_B>: { <skill_B1> : <damage_B1>, <skill_B2> : <damage_B2>, }, .. }, } where <hero_*>'s and <skill_*>'s are strings, and <damage_*>'s are a non-negative integers. For example, if <hero_A> performs an attack with <skill_A1>, the amount of damage from that attack is <damage_A1>. The game keeps a combat_log which basically is a list heros' actions. Each action is a tuple (hero_name, skill_name) which means that hero_name performs skill_name . The total damage is simply the sum of all damages dealt by all the attacks in the combat log. Your task is to write a function total_damage(skill_book:dict[str,dict[str,int]], combat_log:list[tuple[str,str]]) -> int that computes the total amount of damage dealt from all actions in the given combat_log according to the skill_book written in the aforementioned format.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,