Python itself has a lot of different tools, a lot of different functions. For example, you've already seen some of the functions for reading CSV files. Python also has a lot of math tools. For example, those who have you ever seen or used an old-school calculator like this one? For a long time I was using a calculator on my phone. But now these days, if I need to do some math, I pretty much always just do it in Python. And beyond that, Python also has functions to do statistics or to draw simple graphics, and much more. These built-in packages are maintained by the team that supports the Python programming language. And you won't need all of these packages at once in most programs you might write. So you can choose which tools to import based on what you need for a given piece of code. In this lesson, we'll see how to import code that can help you with math and statistics. I will also introduce randomness that is desirable randomness into your code. The concepts and code examples in this lesson will create a foundation for the next one to come in which will then look at third party packages that you can download and install from the internet. Let's take a look. Python comes with many packages that are built-in and pre-installed for you to use. You can think of each package in Python as akin to a book. And so Python comes with a lot of different books on different subjects, just as if you are doing research in a library. You may not need to use every single book for every single piece of research you're doing. When you're writing a specific piece of code, you may need to use only a subset of the packages available. Let's start by looking at an example of using Python to do math. Here, I'm going to import from the math package the functions cosine, sin as was turns out this is just a number, the floating point number pi. In Python's terminology sometimes you hear the words module, package, and library. And these terms aren't used completely, consistently. And technically you see people online call this the math module. But for the purpose of this course, I'm going to use mainly the term package. If you want to know the exact definition of what's a module versus package versus a library, do ask an AI chatbot, they give you a clear definition. So when I run this line of code, I'm importing cosine, sin and pi from the math package. Technically, the math module, but let's not worry about that. And if I print pi, turns out this is just a sorting of point number. Does a pretty accurate value for pi, the ratio between a circle's circumference and diameter. And if I now set values to be equal to zero pi over two, which is 90 degrees pi, which is 180 degrees, 270 degrees and 360 degrees, then you can now do something like this where you can use the cosine function that we just imported to compute the value of the cosine of different angles. And just for fun, feel free to run this code and then change this to print out the sin of these different angles using the sin function that we had imported up here. Now one more example. It turns out Python also has a function for rounding numbers down. So we want to take the number 5.7 and rounded down. This should be five. You can use the floor function, which is also part of the math package or the math module. But if you run this, this won't work because of now you've imported the floor function. But if I were to say from math import floor and run that and then run this now, then this will work. This runs it down to five. In addition to math, Python also has a built-in package for statistics. So I'm going to from the statistics package import mean and standard deviation. And if I have a set of friends whose heights are given in this list, these are heights in centimeters. They can compute the mean of my friend's heights or compute the standard deviation of my friends heights. The Python statistics package has a few other functions to compute the median, to compute quantiles of data, and a few other things that you might find useful. If you're doing simple statistics on data. Lastly, for this one fun thing, there's also a Python package for introducing randomness into your code. So I'm going from random import to sample function. Let's ask a chatbot how do you use the function sample from the random module in Python. Okay, from random import sample. Given a list, you can say what's a sample size, random samples equals, and so on. You can pause the video and read through these instructions in detail if you want. Or ask an AI chatbot yourself, but let me show you how you can use the sample function for a fun application of creating new recipes. You might remember one of the early examples we've seen was if you have spices, vegetables and proteins, we could feed some list of ingredients to a large language model and have it create the recipe. But what if you don't want to pick the spices and vegetables and proteins? I'm going to say from the spices, let's pick a set of random spices. I am going to type sample from the list of spices that we define on top. Let's pick two spices. And then similarly let's pick a set of random vegetables. I'm going to look at the list of vegetables we define on top. And let's pick two vegetables. And lastly from the list of proteins we defined here the sample one random protein. And if I run this I actually have no idea what I'm going to get. So if I were to print random spices. Okay. We got paprika and oregano. And let's now print random vegetables, broccoli and carrot. That sounds pretty good. And protein. Hm, beef. And so for these randomly chosen ingredients, let's use a large language model to suggest a recipe that uses spices, vegetables, and proteins. So this is a prompt. And now let's call the large language model get LLM response to prompt print recipe. It turns out if I actually run this, it won't work, because in this notebook was not yet imported get LLM response. So to actually make this work, we need to run from helper functions import get LLM response, and if I run this then it will take the random ingredients we just generated and create, you know, a pretty plausible, pretty interesting recipe. When you run this yourself, you'll probably get a different answer than I will, because importing the sample function from the random package allows you to write code that generates a different random result every time you run it. So here we have that paprika, oregano, beef stir fry with broccoli and carrots. In fact, if I were to rerun this cell again I now have a different spices, vegetables and proteins. And if I were to generate a new prompt and rerun the LLM response that ends up with a spiced Tempeh Lettuce Wraps, that's a totally different recipe because we've got different random ingredients this time. So the sample function from the random package is a nice way to inject randomness into your code so that it can generate a new result every time. So that's how you can use built-in modules or built-in packages in Python. And I hope you have fun playing with these recipes and all of these code samples. In the next lesson, we'll go beyond Python's built-in packages to third party packages so you can download and install off the internet. This will significantly open up the space of where you can get Python to do for you. I'll see you in the next video.