Answered step by step
Verified Expert Solution
Question
1 Approved Answer
make python script to process the data in the XML. The file name is leading_causes_of_death.xml At the first of the file (after any import statements)
- make python script to process the data in the XML.The file name is leading_causes_of_death.xml
- At the first of the file (after any import statements) define three functions
- main()
- process_row(row)
- print_rows(row_list)
- In themainfunction:
- Ask the user to input a year ("Please enter a year: ")
- An empty list variable calledcod_listshould be initialized
- Aforloop should be used to move through therowelements of the xml file.
- Each row in the xml file should be passed to theprocess_rowfunction. Theprocess_rowfunction should return a dictionary. Each dictionary should then be appended to thecod_list
- After theforloop thecod_listshould be passed to theprint_rowsfunction
- Also pass the inputted year as a parameter to the print_rows function
- In theprint_rowsfunction
- A for loop to move through each dictionary using the enumerate function to keep track of the index
- If the year matches the user inputted year, print out the record index, the id of the row, and the informational text that follows this pattern:
- Record 2 (id: 15031): During 2016 the leading cause of death in Arizona was Unintentional Injuries
- Within theprocess_rowsfunction:
- Every element in a row should become a key-value pair (example: 'year', 'state', and 'deaths' are all examples of keys and the associated text would be their values within the dictionary)
- Also, each dictionary item should also include a key-value pair specifying the id of the row.
- Code minimalism requirements:
- You should use the if __name__=='__main__':syntax to call your main method
- Do not use global variables. If a function needs a variable then pass it as a parameter.
- The only code at the far left indent should be functions, import statements, and the if statement that calls the main function
- Do not use inner functions (a function within a function)
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