 This video shows one solution to lesson three, practice exercise A, which determines the percentage of cities in the state of Washington that have park and ride facilities. This solution uses the syntax currently shown in the ArcGIS Pro documentation for the select layer by location tool, in which the feature layer returned by the tool is stored in a variable and then used in an update cursor. Looking at the solution, I start by importing the ArcPy site package. Then I added line six to set the overwrite output property to true, which is a good idea when you're writing scripts like these where you'll be doing some testing and you'll often want to overwrite the output files. Otherwise, ArcGIS is going to return an error message saying that it can't overwrite an output that already exists. So that's one tip you can take away from this code. On line seven, I set the workspace to the Washington final geodatabase that stores the data using the exercise. That enables me to refer to the input feature classes using only their names, not their full paths. This script doesn't produce any new output feature classes, but if it did, I can likewise specify them using only their names, not their full paths. So in lines eight and nine, I define variables to refer to the city boundaries and park and ride feature classes. Now, the purpose of this script is to update a field in the city boundaries feature class called has park and ride with either a true or a false value. So on line 10, I define a park and ride field variable to store the name of that field that I'm going to be updating. I also want to report the percentage of cities containing a park and ride at the end of the script through a print statement. So on line 11, I define a variable to store account of those cities and I initialize that variable to zero. Now, before I talk about the meat of the script, it's often helpful to walk through your processing steps manually and pro. So here I have the park and ride park and ride symbolized by black dots and city boundaries that are the orange polygons. So I can use the select by location tool and specify that I want to select city boundaries features that contain park and ride features. And when that's done, you can see that all the city features, some of the city features selected, and I can open up the attribute table to see the selected tabular records. And then I could go and do some further operations on just selected records. We can see that we have 74 out of 108 city boundaries selected. So getting back to my script. I'm going to implement the same select by location tool. It's going to return to me a feature layer of cities that contain a park and ride, which I store in my city layer cities layer variable here on line 15. I then open up an update cursor on that feature layer. This update cursor will only be able to update the fields that I specify in the second parameter. I could include any number of fields here as a tuple, but for this scenario, I really only need to include one. And the name of that field is stored in my park and ride field variable, which I defined up on line 10. And so what I have is a cursor that I can iterate through row by row, and I do that using a for loop with which starts online 19 and online 21. I take that has park and ride field. And I set it to true. Now, why do I say zero there in square brackets. Zero is the index vision position of the field that I that I passed into that tuple in line 18. The first in this case the only field in the tuple is that position zero. If I was wanting to update three or four fields, I would have, I would use my row variable and then the field index position inside brackets might be a one or two or three and so on. So after I've made my changes, I need to call update row in order for them to be applied mistake a lot of beginners make as they forget to do this step. So line 22 and calling update row and line 23 I'm incrementing the counter that I'm using to keep a count of the number of cities with a park and ride. So I just add one to the counter. The plus equals operator is just a shortcut for saying take the number in this variable and add one. I mentioned that I was using try and accept to provide a custom error message. An important part of the script that goes along with this try and accept block is the finally block aligns 28 through 30. This contains code that I want to run whether or not the above code failed. I don't want to leave a lock in place on the city's feature class. So I delete the feature layer based on it online 29. I also use a Python Dell statement to clear the row and cursor objects out of memory for the same reason I used the delete tool to make sure no locks are left on the future classes. Now I could have put these statements in my try block. Say after the update cursor and assuming there weren't any problems in running my code those cleanup statements would get executed to. For let's say there's a problem in my in my update cursor, if the script crashes there, then my cleanup statements won't get executed. And if I try to run the script again I could run into a problem with the city's feature class having a lock on. So putting the cleanup statements in the finally block ensures that they'll get executed in that situation. Now that I've done all the important stuff. Down here online 33 it's time to do some math to figure out the percentage of cities that have a park and ride. So online 33 I'm running the get count tool in our jazz. When you use the get count tool, it's a bit unintuitive because what it returns isn't a number but a result object. What you can do with that object isn't well documented so you can just follow along with this example here and use zero and square brackets to get at the count in string form again not very intuitive. And then use the int function to convert that into an integer. And that'll give me the number of features in my total number of features in my city boundaries feature class. So what we have in the end online 34 is a variable called non cities, that is the total number of cities in the entire data set. And then we've already been keeping this counter cities that have a park and ride. So to find the percentage all you do is divide one by the other. And that's happening online 40. This line 37 refers to the cities with park and ride variable, but it's coming out. It turns out that the object returned by select layer by location and select layer by attribute isn't just the feature layer of selected cities, like the get count tool we just saw the select tools actually return result object. This object can be treated kind of like a list. If you want the feature layer, you can specify zero in square brackets, or simply not include a number of brackets at all. But you can also get a count of the selected features by specifying to in square brackets. You can see this in the documentation of the tool in the derived output section, which comes after the syntax. So we're using the count output parameter, which is that position to. So it turns out we don't really need to implement our own counter inside the loop through the cursor rows. We can get the count through the result object. And thus we could, we could uncomment line 37 and comment out lines 23 and 11. So we decided to include the counter approach in the solution because as a program where there's bound to be times where you really do need to maintain your own counter. And we wanted you to see an example of how you might go about doing that. Okay, so finally, we can print out the result at the end of the script in line 42. The percentage is a number with several digits after the decimal point. The print statement first rounds the number to one digit after the decimal, and then converts that value to a string. So it can be concatenated with the literal text of the message.