PYTHON In order to parse data to start a simulation, users must enter data correctly. Suppose that the simulation requires 2 information from the user, which is called 'soil_key' and 'soil_data.' The user will enter 'soil_key' first, following with 'soil_data.' We need to check if the user enters the 'soil_data' data correctly. All elements in soil data ('soil_data') must be characters defined in the soil keys ('soil_key'). Both soil_key and soil_data are lists. Consider an example: INPUT: soil_key = ['C', 'Clay', ' B', 'Bedrock', ' V', 'Void'] soil_data1 = [ ['V', 'C', 'V'], ['C', 'V', ' '], ['B', 'M', 'B'] ] soil_data2 = [ ['B', 'C', 'V'], ['C', 'V', ' B'], ['B', 'C', 'B'] ] OUTPUT: soil_data1: check data again. Parsing failed! soil_data2: Parsing successfully. Write a python function that checks if the soil data is being entered correctly. Return True and print 'Parsing successfully' for correct data. Otherwise, return False and tells the user 'check data again. Parsing failed!'
PYTHON
In order to parse data to start a simulation, users must enter data correctly.
Suppose that the simulation requires 2 information from the user, which is called 'soil_key' and 'soil_data.' The user will enter 'soil_key' first, following with 'soil_data.' We need to check if the user enters the 'soil_data' data correctly. All elements in soil data ('soil_data') must be characters defined in the soil keys ('soil_key'). Both soil_key and soil_data are lists. Consider an example:
INPUT:
soil_key = ['C', 'Clay', ' B', 'Bedrock', ' V', 'Void']
soil_data1 = [ ['V', 'C', 'V'], ['C', 'V', ' '], ['B', 'M', 'B'] ]
soil_data2 = [ ['B', 'C', 'V'], ['C', 'V', ' B'], ['B', 'C', 'B'] ]
OUTPUT:
soil_data1: check data again. Parsing failed!
soil_data2: Parsing successfully.
Write a python function that checks if the soil data is being entered correctly. Return True and print 'Parsing successfully' for correct data. Otherwise, return False and tells the user 'check data again. Parsing failed!'
Step by step
Solved in 2 steps with 1 images