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:
import csv
def create_datastore() -> list:
csv_dicts = []
with open('RiskResults.csv', encoding='utf-8-sig') as csvfile: # opening csv file
dreader = csv.DictReader(csvfile) #reads the file and compares the data to dictionary
for row in dreader: # for loop over dict reader to get the table
csv_dicts.append(row)
return csv_dicts # returns to array to make table
data_store = create_datastore()
threat_dict = {
"Emergency": {"Frequent": 16, "Probable": 14, "Likely": 12, "Unlikely": 10, "Rare": 8},
"Major": {"Frequent": 14, "Probable": 12, "Likely": 10, "Unlikely": 8, "Rare": 6},
"Moderate": {"Frequent": 12, "Probable": 10, "Likely": 8, "Unlikely": 6, "Rare": 4},
"Minor": {"Frequent": 10, "Probable": 8, "Likely": 6, "Unlikely": 4, "Rare": 2},
"Negatable": {"Frequent": 8, "Probable": 6, "Likely": 4, "Unlikely": 2, "Rare": 0}
}
def get_recomendation(val): # displays recomendation based on threat value
if (val > 15):
print("Major bug or issue - sending email to sysadmin, infosec chief, and IT manager")
elif (val > 4):
print("Issue will require increase in security and access controls. Adding to Backlog for further planning.")
elif (val >= 0):
print("Minor issue likely, increasing security is not recommended due to costs involved")
else:
print("Logging Error - check the data provided as this threat value is invalid.")
if __name__ == "__main__":
risk_id = int(input("Please enter risk ID: "))
print(data_store[risk_id - 1]["Description"])
get_recomendation(threat_dict[data_store[risk_id - 1]['Severity']][data_store[risk_id - 1]['Probability']])
RiskResults.csv
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 10:16 1/12/2023 10:26 Building Maintenance Major Unlikely Maintenance 10 1/12/2023 10:12 1/12/2023 10:29 Flooding Emergency Probable Disaster
Error message:
File "c: \Users \12394\Desktop\RiskValue isk.py", line 34 , in module> print(data_store[risk_id - 1]["Description"]) KeyError: 'DescriptionStep 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