Let's take a look at our code. Now, I have already implemented two callbacks in this example. This is callbacks.pie. Here we have our original code, area of circle and price of a round pizza. I have implemented print to area of a circle, simply calls our code and prints out the result. Similarly for price a pizza, it calculates the information and prints it out. Here is a for-each function and this is the core of our example. The for-each function takes the dataset and takes an operation. It's going to accept the function as a parameter, and it's going to loop over the dataset. For each element in the dataset, it's going to execute the operation. Now, I don't expect you to understand the try and the except because we haven't covered them but basically this is exception handling. If there should be an exception, all you need to know is that if there's a problem, we execute the operation, the code underneath except we'll be brought into play and we'll handle it. Then we'll be able to continue looping even if for one given element, things blew up. It won't terminate our application. Here are the various pizza sizes that we're going to work with. We can go ahead and run it. There it goes, printing out the areas and the prices. You'll notice, yes, personal pan pizza blows up because that's not a number that we can work with. This is our own message, it must be an integer or a float. Having seen that, I'm going to go ahead and take the bad data out of our example but that does illustrate a nice point. We can write our code, the print an area or the price of pizza and not worry about either iteration or the possibility of an exception. The for-each handled all of that for us. We're taking advantage of code that someone else, in this case, me, wrote so that our callback code can be simpler. Here's our task. The owner of our pizza joint is determined that the ideal pizza slice has an arc of just over three inches after it's folded. In other words, just over six inches before it's folded, and wants to know what sizes of pizza work best given that finding. Our task is to write a function that helps make that calculation. Conveniently, the number pi is just over three inches, we're going to say that the ideal width of a slice of pizza is two pi before folding. For any given pizza, how many ideal slices can we get from that? How much is left over? If the waste is less than half an inch, we're going to ignore it as A, it's easily subsumed into the slice, and B, it means we can ignore any rounding errors with floating point math. Let's put together now a function to do this calculation. Number of ideal slices. The width is two pi rounded off, how many decimal places we care about? The circumference of the pizza is the diameter times pi. The slices is going to be circumference divided by width forced to be an int. You can't have fractional slices and the waste is what's leftover. We're going to print out how many of these ideals slices we can get, and if the waste is more than a half an inch we'll print it out but otherwise, we ignore it. Let's go ahead and call this. Let's implement our callback pattern. We've got the function now let's use it. For each pi sizes. It's our method, number of ideal slices. We run it. Here we find out that eight inch and nine inch pieces can go into four, but notice the odd numbers all waste well, roughly pie. The odd numbers all waste. Turns out something else, when you cut a pizza, a around pizza, you generally cut across it with a wheel. You'd have two, four, six, eight in terms of how you cut it. You're cutting it for even numbers of slices. We can discard the pizza sizes as inefficient. The ones that have a waste, which are any with an odd number of inches for the diameter, but we can also discard the 10-inch pie because it wants to do five slices or the 14-inch pie, which gives us seven. The pie sizes that are useful are the eight, the 12, the 16, and the 20. Twenty-inch pies are sometimes used in pizza joints, particularly in the New York area for cutting slices. Look at that, we've got just a little bit of code here, but we actually ended up with something useful. What are the optimal sizes of pizzas? That's why you typically will encounter 12-inch mediums, 16-inch larges in pizza joints, and you're not running into the sizes here that we're considering non-optimal. Real value even from such a simple program. This concludes our Fundamentals of Programming presentation. In your lab, you'll continue from this point in the program and add another feature. The next course in our curricula will cover concepts of object oriented programming.