#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
icon
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,