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
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
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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F48954d8a-c361-4523-b68b-ac12d6ced482%2F46d4c2cf-c9ad-421b-aed8-41495d93ed7d%2Fgnd0ikb_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education