#Imagine we're writing some code for a video game. #In this video game, there are six elements, which #come in three pairs: Fire and Ice; Land and Water; #Time and Space. Each pair of elements cancels #themselves out: if an attack does 3 Fire damage and #3 Ice damage, then it does 0 total damage. # #Write a function called calculate_damage. #calculate_damage should take as input a list of #2-tuples. The first item of each 2-tuple will be an #integer; the second will be a string, either "Fire", #"Ice", "Land", "Water", "Time", or "Space". 1 #Your function should return a list of three 2-tuples: #the first will represent the total Fire or Ice #damage, such as (3, "Ice") or (2, "Fire"). The #second will represent the total Land or Water damage, #such as (3, "Water") or (2, "Land"). The third #will represent the total Time or Space damage, #such as (3, "Time") or (2, "Space"). # #You may assume that there will always be some net #damage for each of the three categories (e.g. you #don't have to handle the case where there is 0 Fire #or Ice damage). #For example, for the following list of 2-tuples... # # attacks = [(3, # (2, "Fire"), (2, "Ice"), (5, "Water"), "Land"), (1, "Time"), (2, "Space")] # calculate_damage (attacks) -> [(1, "Fire"), (3, "Water"), (1, "Space")] # #Because: #3 Fire 2 ce 1 Fire #5 Water + 2 Land = 3 Water #1 Time + 2 Space = 1 Space # #HINT: For each of the three pairs, try thinking of #one as positive and the other as negative.
#Imagine we're writing some code for a video game. #In this video game, there are six elements, which #come in three pairs: Fire and Ice; Land and Water; #Time and Space. Each pair of elements cancels #themselves out: if an attack does 3 Fire damage and #3 Ice damage, then it does 0 total damage. # #Write a function called calculate_damage. #calculate_damage should take as input a list of #2-tuples. The first item of each 2-tuple will be an #integer; the second will be a string, either "Fire", #"Ice", "Land", "Water", "Time", or "Space". 1 #Your function should return a list of three 2-tuples: #the first will represent the total Fire or Ice #damage, such as (3, "Ice") or (2, "Fire"). The #second will represent the total Land or Water damage, #such as (3, "Water") or (2, "Land"). The third #will represent the total Time or Space damage, #such as (3, "Time") or (2, "Space"). # #You may assume that there will always be some net #damage for each of the three categories (e.g. you #don't have to handle the case where there is 0 Fire #or Ice damage). #For example, for the following list of 2-tuples... # # attacks = [(3, # (2, "Fire"), (2, "Ice"), (5, "Water"), "Land"), (1, "Time"), (2, "Space")] # calculate_damage (attacks) -> [(1, "Fire"), (3, "Water"), (1, "Space")] # #Because: #3 Fire 2 ce 1 Fire #5 Water + 2 Land = 3 Water #1 Time + 2 Space = 1 Space # #HINT: For each of the three pairs, try thinking of #one as positive and the other as negative.
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.5: Case Studies
Problem 3E
Related questions
Question
100%
![#Imagine we're writing some code for a video game.
#In this video game, there are six elements, which
#come in three pairs: Fire and Ice; Land and Water;
#Time and Space. Each pair of elements cancels
#themselves out: if an attack does 3 Fire damage and
#3 Ice damage, then it does 0 total damage.
#
#Write a function called calculate_damage.
#calculate_damage should take as input a list of
#2-tuples. The first item of each 2-tuple will be an
#integer; the second will be a string, either "Fire",
#"Ice", "Land", "Water", "Time", or "Space".
#
#Your function should return a list of three 2-tuples:
#the first will represent the total Fire or Ice
#damage, such as (3, "Ice") or (2, "Fire"). The
#second will represent the total Land or Water damage,
#such as (3, "Water") or (2, "Land"). The third
#will represent the total Time or Space damage,
#such as (3, "Time") or (2, "Space").
#
#You may assume that there will always be some net
#damage for each of the three categories (e.g. you
#don't have to handle the case where there is 0 Fire
#or Ice damage).
#
#For example, for the following list of 2-tuples...
#
#attacks = [(3, "Fire"), (2, "Ice"), (5, "Water")
(2, "Land"), (1, "Time"), (2, "Space") ]
#
# calculate_damage (attacks) -> [(1, "Fire"), (3, "Water"), (1, "Space")]
#
#Because:
#3 Fire +2 Ice = 1 Fire
#5 Water + 2 Land = 3 Water
# 1 Time + 2 Space = 1 Space
I
#HINT: For each of the three pairs, try thinking of
#one as positive and the other as negative.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F22018d06-6934-4018-9122-ab9dd37c1915%2F74f60030-ba17-4b68-95a8-8991f8e3a183%2Falsw1m_processed.png&w=3840&q=75)
Transcribed Image Text:#Imagine we're writing some code for a video game.
#In this video game, there are six elements, which
#come in three pairs: Fire and Ice; Land and Water;
#Time and Space. Each pair of elements cancels
#themselves out: if an attack does 3 Fire damage and
#3 Ice damage, then it does 0 total damage.
#
#Write a function called calculate_damage.
#calculate_damage should take as input a list of
#2-tuples. The first item of each 2-tuple will be an
#integer; the second will be a string, either "Fire",
#"Ice", "Land", "Water", "Time", or "Space".
#
#Your function should return a list of three 2-tuples:
#the first will represent the total Fire or Ice
#damage, such as (3, "Ice") or (2, "Fire"). The
#second will represent the total Land or Water damage,
#such as (3, "Water") or (2, "Land"). The third
#will represent the total Time or Space damage,
#such as (3, "Time") or (2, "Space").
#
#You may assume that there will always be some net
#damage for each of the three categories (e.g. you
#don't have to handle the case where there is 0 Fire
#or Ice damage).
#
#For example, for the following list of 2-tuples...
#
#attacks = [(3, "Fire"), (2, "Ice"), (5, "Water")
(2, "Land"), (1, "Time"), (2, "Space") ]
#
# calculate_damage (attacks) -> [(1, "Fire"), (3, "Water"), (1, "Space")]
#
#Because:
#3 Fire +2 Ice = 1 Fire
#5 Water + 2 Land = 3 Water
# 1 Time + 2 Space = 1 Space
I
#HINT: For each of the three pairs, try thinking of
#one as positive and the other as negative.
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 4 steps with 2 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
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,