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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education