Bird
0
0

Consider this simplified risk assessment code snippet:

medium📝 Analysis Q13 of 15
Cybersecurity - Compliance and Governance
Consider this simplified risk assessment code snippet:
assets = {"Server": 100000, "Laptop": 2000}
threats = {"Hack": 0.1, "Theft": 0.05}
risk = {a: assets[a] * threats[t] for a in assets for t in threats}

What will be the value of risk["Server"] after running this code?
AThe last calculated risk value for Server, because keys overlap in the dictionary comprehension
BAn error because of incorrect dictionary comprehension
CThe last calculated risk value for Server multiplied by all threats
DA dictionary with combined risks for each threat
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the dictionary comprehension

    The comprehension creates keys from assets only, but loops over all threats, so keys repeat for each threat.
  2. Step 2: Understand key overwriting in dictionaries

    Since keys are just asset names, each new threat overwrites the previous risk value for that asset, leaving only the last threat's risk.
  3. Final Answer:

    The last calculated risk value for Server, because keys overlap in the dictionary comprehension -> Option A
  4. Quick Check:

    Overlapping keys overwrite values in dict comprehension [OK]
Quick Trick: Check if keys repeat in comprehension loops [OK]
Common Mistakes:
MISTAKES
  • Assuming all risks combine in one dict
  • Ignoring key overwriting behavior
  • Expecting a syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cybersecurity Quizzes