Question
PLEASE DO NOT SPAM THE QUESTION I WILL AUTOMATICALLY DISLIKE IT (THANKS) The following Python script needs to be FIXED. It Reads a CSV file(down
PLEASE DO NOT SPAM THE QUESTION I WILL AUTOMATICALLY DISLIKE IT (THANKS)
The following Python script needs to be FIXED. It Reads a CSV file(down below) into a list of dictionaries to map the severity and probability to the threat value, and stores the threat value, threat description, severity, and probability in a dictionary. It calculates a threat value based on the severity and probability of each threat, stores the threat information in a dictionary, and outputs a recommendation for each threat based on its threat value. The recommended actions range from minor security increases to emailing the sysadmin, infosec chief, and IT manager.
code:
# Define a mapping of severity and probability to threat value
threat_map = {
"Emergency": {"Frequent": 16, "Probable": 14, "Unlikely": 11, "Rare": 8},
"Major": {"Frequent": 14, "Probable": 11, "Unlikely": 8, "Rare": 5},
"Moderate": {"Frequent": 11, "Probable": 8, "Unlikely": 5, "Rare": 2},
"Minor": {"Frequent": 5, "Probable": 2, "Unlikely": 1, "Rare": 0}
}
# Initialize a list to store the threats information
threats = []
# Open the CSV file and read the data into a list of dictionaries
with open("RiskResults.csv") as file:
# Skip the header line
next(file)
for line in file:
parts = line.strip().split(",")
# Unpack the data into separate variables
ID, start_time, end_time, description, severity, probability = parts
# Calculate the threat value based on the mapping
threat_value = threat_map[severity][probability]
# Create a dictionary to store the threat information
threat = {
"ID": ID,
"start_time": start_time,
"end_time": end_time,
"description": description,
"severity": severity,
"probability": probability,
"threat_value": threat_value
}
# Add the threat information to the list
threats.append(threat)
# Iterate over the list of threats and output a recommendation for each threat
for threat in threats:
threat_value = threat["threat_value"]
if threat_value
# Threat value should not be less than or equal to 0
print("Logging Error - check the data provided as this threat value is invalid.")
elif threat_value
print("Minor issue likely, increasing security is not recommended due to costs involved")
elif threat_value
print("Issue will require increase in security and access controls. Adding to Backlog for further planning.")
else:
print("Major bug or issue - sending email to sysadmin, infosec chief, and IT manager.")
csv file:
ID Start time Completion time Provide a "Description of the Risk" Select its severity Select its Probability Category 1 1/7/2023 12:03 1/7/2023 12:11 Internal employee sabotaging or leaking confidential data Major Unlikely People 2 1/12/2023 9:51 1/12/2023 9:54 Sensitive data over home network (potentially unsecured) Major Frequent Network 3 1/12/2023 10:16 1/12/2023 10:16 There is no security system protecting the house. Moderate Unlikely Physical 4 1/12/2023 10:13 1/12/2023 10:16 Natural disaster in florida Emergency Frequent Disaster 5 1/12/2023 10:16 1/12/2023 10:16 Hurricane Emergency Likely Disaster 6 1/12/2023 10:16 1/12/2023 10:16 Natural disaster Moderate Unlikely Disaster 7 1/12/2023 10:16 1/12/2023 10:16 Hurricane Emergency Unlikely Disaster 8 1/12/2023 10:16 1/12/2023 10:16 Baseball smashing through a window Minor Unlikely Physical 9 1/12/2023 9:51 1/12/2023 10:17 The homeowners face a risk of flood or hurricane damage because they bought a house in Florida. The homeowners can have influence over this by preparing ahead of a hurricane or acknowledging their location in a flood zone (if applicable). Emergency Frequent Disaster 10 1/12/2023 10:16 1/12/2023 10:17 Hurricane Emergency Probable Disaster
Error message:
File "c: \Users \12394\Desktop\RiskValue\tempCodeRunnerFile.py", line 19 , in ID, start_time, end_time, description, severity, probability = parts ValueError: not enough values to unpack (expected 6 , got 1)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started