#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.

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%
#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
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