Question
Need help implementing the function below I really don't understand the specifications. I also cannot import any other libraries that python has. I can only
Need help implementing the function below I really don't understand the specifications. I also cannot import any other libraries that python has. I can only use what they have imported which is import json.
import json
def write_json(data,filename): """ Writes the given data out as a JSON file filename. To be a proper JSON file, data must be a a JSON valid type. That is, it must be one of the following: (1) a number (2) a boolean (3) a string (4) the value None (5) a list (6) a dictionary The contents of lists or dictionaries must be JSON valid type. When written, the JSON data should be nicely indented four spaces for readability. Parameter data: The Python value to encode as a JSON file Precondition: data is a JSON valid type Parameter filename: The file to read Precondition: filename is a string representing a path to a file with extension .json or .JSON. The file may or may not exist. """ pass # Implement this function
Below are the json files they provided
{ "2018-01-01T00:00:00-05:00": { "visibility": { "prevailing": 1.75, "units": "SM" }, "wind": { "speed": 13.0, "crosswind": 5.0, "units": "KT" }, "temperature": { "value": -15.0, "units": "C" }, "sky": [ { "cover": "clouds", "type": "broken", "height": 1200.0, "units": "FT" }, { "type": "overcast", "height": 1800.0, "units": "FT" } ], "weather": [ "light snow", "mist" ], "code": "201801010456Z" }, "2017-12-31T23:00:00-05:00": { "visibility": { "prevailing": 1.75, "units": "SM" }, "wind": { "speed": 13.0, "crosswind": 5.0, "units": "KT" }, "temperature": { "value": -15.0, "units": "C" }, "sky": [ { "cover": "clouds", "type": "broken", "height": 1300.0, "units": "FT" }, { "type": "overcast", "height": 2200.0, "units": "FT" } ], "weather": [ "light snow", "mist" ], "code": "201801010356Z" }, "2017-12-31T22:00:00-05:00": { "visibility": { "prevailing": 3.0, "units": "SM" }, "wind": { "speed": 11.0, "crosswind": 7.0, "units": "KT" }, "temperature": { "value": -15.0, "units": "C" }, "sky": [ { "type": "overcast", "height": 1300.0, "units": "FT" } ], "weather": [ "light snow", "mist" ], "code": "201801010317Z" }, "2017-12-31T21:00:00-05:00": { "visibility": { "prevailing": 10.0, "units": "SM" }, "wind": { "speed": 10.0, "crosswind": 7.0, "units": "KT" }, "temperature": { "value": -16.1, "units": "C" }, "sky": [ { "type": "overcast", "height": 1700.0, "units": "FT" } ], "code": "201801010156Z" } }
2nf json file
[ { "cover": "clouds", "type": "broken", "height": 1200.0, "units": "FT" }, { "type": "overcast", "height": 1800.0, "units": "FT" } ]
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