Start your Coding Journey Here: Python Programming for Beginners | Jae Lee | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Start your Coding Journey Here: Python Programming for Beginners

teacher avatar Jae Lee, I post more on yt, follow me there!

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

8 Lessons (51m)
    • 1. Python Programming: Intro

      1:01
    • 2. Let's Get an IDE!

      3:33
    • 3. Hello World, My First Code

      7:27
    • 4. Texts in Programming: Strings

      6:01
    • 5. Number and Letters: Data Types

      6:54
    • 6. Conditional Coding: If Statements

      8:16
    • 7. Iteration Part 1: Functions

      8:28
    • 8. Iteration Part 2: Loops

      9:14
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

151

Students

--

Projects

About This Class

Check out my coding youtube channel: https://www.youtube.com/channel/UChp_zoGLr7sgMba3Tarl7YA

Start with one of the easiest programming languages: Python. You need to stop researching on how and when to start coding! You need to just start and get your hands dirty by writing some actual lines of code. Join me in this beginner-friendly course.

Meet Your Teacher

Teacher Profile Image

Jae Lee

I post more on yt, follow me there!

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Python Programming: Intro: So you had thousands of people telling you that coding is going to be such a high-income scale the future. And that's going to be so important to know how to code. But you didn't know where to start. You don't know what language to choose. You didn't know what resources to use. And you spent a lot of time doing this research. But in my experience, the best way to learn coding is to just start and you need to start coding. You need to get your hands dirty and start typing some code. So this is where I step in where I made the simple skill share cores, where talk about the easiest language to get in Python. Or I designed the course where one video contains not only one concept, small Coding Challenge, where you can apply what you've learned immediately rather than just learning and watching a video and not being able to do anything about it. And I made these concepts and challenges so easy and so beginner friendly that someone who has never touched a computer can even follow along. So stop researching on what languages to use and what's the best language to start with. Just start with this Python skills should of course, where I teach you on how to become a fluent Python programmer. 2. Let's Get an IDE!: Our guys, before we talk about any kinda Python, lets first download our compiler. We don't know what a compiler is. A compiler is basically an environment that allows us to write Python language in simpler terms. If you have a pencil, you gotta write it's on a surface, right? Basically laid a paper or notebook. Basically that notebook is the compiler when it comes to writing Python. So I'm going to show you guys my stream and just walk you through how you would download a compiler. A compiler is also known as an IDE, which stands for Integrated Development Environment. A famous Python IDE that a lot of people use, a lot of programmers, even professional programmers use PyCharm, just go to Google and search Python like this pie chart. And then really the first link, you just want to click this. And then you would go to download. This has three, whatever. Unless you're using GIS analyst community, we're not going to need anything related to professional. You can just download the community version and you click it and it's gonna start downloading. Because every download and.dmg file before we're just going to click it. And so you just read about this vacation. And then you're going to have open PyCharm and you're just going to open right here. You don't need to importantly settings. There's purse. Okay, in this section we're actually just gonna click skip remaining and set defaults to how this course is going to work is I'm gonna slowly walk you guys through different exercises and challenges encoding. So basically I'm going to give you guys the assignment and then you're going to have to pause the video. And then you try it on your own. And when you try it on your own, you're gonna do it here on this PyCharm app braid. And then if you guys get the correct outputs or basically the correct answers, are going to return to my video and check if your solutions are similar. Or if you gather suddenly I could always come back to the My Course videos and just check what you were missing, et cetera, up to, let's say I give you an exercise to just have your Python print ten plus ten. So what you do is you create new project for this section. You can just leave everything added as it is. And then create if you guys like, you know, seeing them as tips. Us and Lisa, personally, I don't need to see it, so I just close it like that. Now that you're brought here, if we're going to start making a Python file and on that Python file we're going to start writing our code. You're gonna do File New. And you're going to just do a Python file. Just name it like a test ground or any, you know, any names, templates ten also works. And then now you're going to have this area where you can just write freely any type of Python coding. But a lot of the challenges that I'm going to ask you, I'm going to ask for print statements. So basically making your computer print out outputs. And what you're gonna do is just basically compare your output and the exercises solutions output and make sure that their same, making sure your program works. Now, for in this case, I'm going to print, make the computer print ten plus ten. And obviously the answer that we expect is 20 misprint. And let's say this is a code that you wrote on. The way you would test. This is basically click Run and then go here. And then here on the bottom is your console log. Your console log is basically where you can see your outputs. And obviously we've got the answer 20. So now that we got that check, you can move on to the next. There's an exercise and like this, this is how this course will operate. So make sure you have this IDE and make sure you're familiar. If you don't know other features, don't worry. All you need to know is that you can make a Python file right on it and run it and just have the console log show. That's all you need for now as the course progresses. And we're gonna talk about other features on the ID. 3. Hello World, My First Code: All right guys, so I guy, so we're finally gonna start actual programming from this lesson on, in today's video, we'll be talking about the print function variables and the input function. So let's start with the print function. If you guys saw the IDE video for this, I gave you guys a little sneak peek of the print function. Physically, the print function is a way for your Python compiler, compiler to access the console log. And what the console log is just simply a way to see visible proof of your code, right? So when you add ten plus ten on your computer, you don't know if it happened. It probably happened. But you don't know that there's no proof that it did happen unless you make your computer printed or something like that, right? Why we use console long when it comes to testing code and is a great way to see if your code is working or not. And the one thing I want to mention with the print function is basically the way you would access. This is just on any line. You would just write print parenthesis, and write whatever you want to print between those parentheses. So let's say I want to print the number 5555 and the console log will print the number 55. Now, when it comes to printing text, which are, which are also called strings, which I'm going to mention later in a later video, is you have to give a quotation marks. So if we could say elements, say hello, rather than just putting hello, you would put quotation marks around it. Hello, right? With knowing that for the first challenge of our course, you guys are going to try to print your name on the ID. So positively, you go try it out if you guys are stuck, we're finished, returned to video and compare it with my solution. So hope you guys were able to figure that out. So the way they do this is basically just right, right. And give a quotation marks around your name, right? Like they said, your name is a text, not a number, right. So you would write something like Tyler, right? Between the quotation marks? Oh yeah. My name is Jason. I do something like this and then just run run test crown. And there we go. So that prints the console log J. Right? Now let's talk about variables and data types. So values can always change in a computer program. Take high scores and games. For example, when you're playing a game and there's a high score, that variable sometimes subject to change rate some of my beat it. That's when you use variables. Without variables, you're going to have to update every number, every time manually, right? So for example, let's say I saved a high score as 23 on that program and someone beat tie score. Now I have to change every 23 into the new highscore, which is gonna take up a lot of the time. That's why we resort to variables. Variable name equals 0. Let's use high scores as an example. Let's sing high score is 30, right? That literally means the variable highscore carries with it the value 30. Now, when it comes to assigning texts, as also of the same principles apply when you're trying to print text. And let's say I wanna assign a variable name and assign my name into it. You wouldn't just put j, you would put quotation marks around it and add j. And when it comes to numbers, you'd like to do that like same with iceberg, my age 20, and I'm just put 20 Excel, I wouldn't put quotation marks around it. Another thing I want to mention when it comes to variables, variables is when you want to print variables. So let's say you have something saved in a variable called greeting, right? So it saves my greeting. Reading people's Hello train. Now, when it comes to printing your variables, you don't have to give a quotation marks. So you'd let say you want to print the variable greeting. You wouldn't have to do all this because breathing is a text, right? Reading is not a text anymore. It's a variable that contains the text hello, right? So that is why you don't need the quotation marks. And this is essentially the reason why you have to put quotation marks into text, right? Because the Python program automatically assumes things without quotation marks as variables. That's why when you print texts that are not variables, you have to add quotation marks, but in this case, greeting his a variable. So you don't want to add quotation marks. So this challenge, I want you guys to initiate a variable x to 60 and a variable y to 40, and initiate a variable sum to the sum of x and y. And then lastly print the value of x1. So pause the video, try it out and compare it to my solution after. So I hope you guys were able to figure that out. Very simple solution. So in order to assign a variable X, I'm gonna have to use the assignment operator, like I said, and we wanted that has 60 sameness. Why do you want that as 40 knots spaces between these assignment operators and the variables don't really matter. You can do x equals 6000 seizing spaces to make it look more clear. And then lastly, some variable that equals the sum of x plus y. Right? Now, I want to print that value so you can print. And then battalion in quotation marks because sum is a variable here. And then what you do is you would run test crown. And there we go, a prince of 100. Great. So if you've got 100, that means you passed. Okay? Now we're going to talk about the input function. You can think input function as a function you need when you need data from a user, right? You know, there are some data variables where the programmer doesn't know and has to ask from the user of the program, right? And most common way of using the input function is basically creating a variable and then assigning it to the input function. Now between these parentheses where you would put the question or the product you want to display to the user. So usually people do something like input, entered your age. And the reason why we put quotation marks as rubber, enter your age isn't a variable. So that's why you want to use quotation marks. So you do input, enter your age, right? And then the variable will be assigned to whatever the user enters. And the way that the user enters a value is basically putting in the value and then pressing Enter. I'm going to show you guys real quick Klein the, I'd say we create a sample that anymore just name Sample, call it pray and put. And it asks for the age. And then we want to just print. So if I run this, the compiler is gonna ask for my age, right? And all I have to do is plug in a value and press Enter, and that's now the printed some value, right? So that's how you would enter the variable as a user, type next to it and then press enter. Now for this challenge, I'm going to ask you guys to ask for the user's name and just save it, save the variable as name, and then you're gonna print the name as before me. Pause the video, try it out and the return against Hope you guys were able to find it. It's very simple. It's very simple example that I just found sample that I just showed you. So you would use something like a name for the variable. And then you would use a input function, right? And then ask the user, what is your name or something like name. And then you would print the name right? Because you want to see a proof if it worked or not. So I would run it. It's going to ask him or her name, and that has same elements j. And then there you go, that is printed. Now the reason why this space exists here is because I've added the space. If yours doesn't have the space, don't worry, right? So that was printing print function variables. And these are very simple challenges. We're going to use these three ideas very often throughout this entire course. 4. Texts in Programming: Strings: Guys, in this section we're going to step into strings. You can basically things strings as text and Python. So because there's a format text, you can't do certain operators like the division sign to multiplication, things like that. However, when it comes to the addition sign, there is something that you can do with two strings. When you add two strings, the computer literally puts them together. And this is very sensitive to what the string is and it will place it right next to each other. An example that I want to show you is if you add hello and we, sorry, even as I've been Hello World, this would literally print hello world, like there is no space. Even though consciously when think OK, if I add hello and world, there must be a space, but the computer doesn't know that. You have to do is usually you'd either have to put a space like in between one of the words or you would have to add the space yourself, like loops, like like so. That's how you would do it. That's basically what adding strings aren't and it's very literal. So keep that in mind. And also numbers can be strings, 1-2-3-4-5. So this, if you add quotation marks wanted, 345 is no longer 12,345 is just a string of numbers that says 1-2-3-4-5. So this wouldn't work is something that you want to focus on. The next thing I want to talk about is string indexing. So what's shrink indexing is, is basically choosing one of the characters inside the string. So what that looks like is it, let's say I saved this string into a variable called numbers, right? I haven't called numbers, and I save it to a string of 1-2-3-4-5. And if I do numbers with the bracket, square bracket sign, this is now I'm trying to index something. Let's use a different number because it might be confusing with the numbers one to five. So if you, if at a string like 66789, the 0th position is not, the first position is not six. The first position is actually seven because Python counselor, first position as the 0th position, right? So that's something you want to keep in mind when you're indexing. But if you want to get other numbers, numbers one would obviously be seven. Number two would be a, number three would be nine. So it is counter-intuitive. You might say like, hey, the first position number is six. It's actually seven because Python starts counting from 0. Now the next thing I want to talk about is piecing. Indexing is good when you're just trying to get that one character hover, you might need a piece of a string. So let's go talk about piecing. So it's the same onset. It's just that you're gonna add a colon. Who's, you know, you're going to need to give it a range, right, to get a piece. So let's say I have a string called numbers, and I have a variable called numbers, and I save it for 6789. And then I want to get a piece of it. So rather than just getting one like 678, I want to get like 678 then what I would use this numbers and the same square brackets, but rather than putting one number, I'm going to give it a range. I'm going to give it the position that I want to start on 608. I'm starting the 0th position. So 0 and that Holon and one more to the place or the position that I want to end on. So 6788 is in the second position, right? Because remember, it starts from 0. So rather than putting too, I would add one more and add three. Think of this range as starting from 0, but ending one before three, right? So this is how you would get a piece of the string with knowing that I have a challenge for you guys. You guys are first going to initiate a variable name and then initiate to a string of your actual name. And then initiate the variable question to the string, How old is with a space at the end? Don't forget that space. Now I want you guys to print this string right here. How old is? The name obviously is based on your name, right? This string right here, by adding the variables question name and a question mark. You guys know how to, what happens when you guys as strings, right? So use what I've told you guys and try to print that train. And lastly, print the word old from the variable question, right? So this is where you have to use the string piecing, where you're going to have to select a certain part of the variable question, same saved as how old is and just print the word old. So pause the video, go try that out and I return. So hope you guys were able to find that out. This one is a bit harder from the previous challenges. First, we want to initiate a variable to my name, right? So how do name? And my name is obviously j and I'd save it as a string. And then I also want to initiate a variable to the question, to question and obviously holding the value of that string. So the variable question and equals, how old towel with the space. Don't forget that space. So there we go. We have initiated both variables to that string. And then we want to print how old is jQuery? And the way we do that is I would print it right. And I will just do question plus name, right? And then plus the character of the question mark at the end, right? I don't need the space for this because you don't put spaces before a question mark, right? And then the last thing I wanna do is print the word older from variable question. So I'm going to start counting from 0 for this string question, right? So 0 h 01234. So all the word Old starts from position four. And let's see where ends 56, Right? But we have to add one more to sit, right? So that's why it's for colon seven. So let's run this, check if our code is working. So we've got the string hello, oldest shape, and we got the string all the panda crater book question. So if you guys got, were successfully able to get those code, you guys nail this challenge. 5. Number and Letters: Data Types: All right guys, in this video we're going to be talking about basic datatype. So we just talked about strings and we realized that, that is something called a datatype. So a data that we can work with or Python can understand. Now the reason why they are different data types is because there are different things you can do. Different data, right? Right. You can add numbers. We can't really add tax rate. That's why you, we need to get Python a separation or a clear distinction between them so that they understand. Ok, I'm about to work with this datatype. These are some of the things that I can do with it as the computer rate. So this is why we distinctive PHI data datatype from other data types. So what I'm sure you guys, we're going to only work with for data types in the beginning, I don't wanna throw so much information at you. Obviously in Python there are more than bored out of taste, but I just wanna give you guys the most basic just to start with Python. So, but number one, data type is an integer. Now what an integer is, is basically like, like the name suggests an integer. Integers are basically numbers that don't include like decimals. And integers can be negative and it also includes 0 sum, right? So all negative whole numbers, 0 and all positive whole numbers, right? And no decimals. So 3.5 is not an integer right? Now, what is 3.53.5 is something called a float. A float value is something we can add decimals to an end. There are limitations to how many places of decimal you can go. Flux can actually carry quite the amount of decimals. But if we need more decimals, there are other data types that can handle more decimal places, but for now we're only going to deal with decimals that have like a to one decimal, place them most float is going to do that for us. What a Boolean is. A Boolean is basically a value that either holds a true value or a false value. So it allows, it allows the computer to realize if something is true or false. And the most common way of using this as usually with conditions. So, you know, in life we always make decisions. So there's computer and some code only runs when a condition is met. And in order to, in order to check that condition, we usually give the program a Boolean value. So Boolean values that are either true or false values. And lastly, we talked about strings already, but string is basically think of it as text, right? So we have these four data site that will work with in the near future. And I also want to talk about conversion functions. So there are some times where we want to convert one data type to the other, right? So example, for example, let's say I have a text string. Let say I have the number five in the string format, so there's no number. Like we said before, we can't divide the string five by numerical five right now won't work because there are different data types. However, we can actually fix that by using data conversion functions. And what that is is basically these right here, right now I just want to talk about three data type functions. The int function, float function, and the stream function in function is basically changing whatever is inside the parentheses into an int. And a float function will change whatever is inside a flowed from Float function until float data type. Let's say I put the string five inside the int function. And this would actually change it into the integer version of five and same with float. And for the string one, there's no point to print a string into a string function, it's early, it's string. So if I put five, this would change it into a string version of five, right? So in order to better understand this, I prepared a challenge for us. So for this challenge, we're first going to ask the user for their favorite number. Now, when we use the NPV function into functions are default receiving strings. So if you save a variable, so variable into an input function, right? And ask a question here. The data type of variable is a string. So keep that in mind when you're doing this challenge. And what I want you guys to do is change the received value into an integer and add five to that number and print that number, okay? And print that number. And then lastly, we're going to, after we print that number, it should convert the number back into a string and then add 0 at the end, right? Not, we're not adding anything. We're like adding strings, right? So rather than like adding 0, we want to understand it like at 0 at the end of a number. So if the number that we got from the previous that was 775, then we lake right, and it's a string, right? 75. We're going to convert this back into a string like this. Oh whoops. And then we're gonna add, we're gonna add the 0 string so that it looks like 70. So it looks like selling 50. So it looks like that we multiplied by ten, but that we actually just added a string, alright, and then I want you guys to print this number as well. So try that out and return to the video if you guys are looking for a solution, all right, you guys you guys were able to figure that out? Let's walk it's let's walk through it step-by-step. So first, we're asked for the users for their favorite number. So I would use something like favorite number and then do an input. Ask users what is your favorite number? But now, once we do that, we want to print adding five to that, right? So remember, this is a string. So what do we have to do? We have to change it to an integer to add five, right? The numerical version of pipe. So we're gonna do is we're going to int, right? But in function to the favorite number. So we're going to change favorite number, which is default by string into an integer, and then plus five. And we want to print this, right? So, but I'm going to save it as variable because we're gonna work with this number later, right? So let's do that. Let's save this as first conversion, okay? Now, after we do that, we want to print first conversion, right? The second conversion we wanna do is change it back into a string. So we're going to do second conversion. Conversion equals the string function of the first conversion, right? And then what we're gonna do is we're going to print second conversion plus the string value of 0. Alright, so this is what the solution looks like. Let's try running it. And let's run that. I'm going to put in 70 so that we get the example where we get the same answers as I gave an example. So I thought it would do 70 Obviously when addFive, which is how many, VI, which is the number that we want. And we got some 50, which intrinsically isn't 750. We just added a 0 at the end, right? But you guys are able to see that we can change that the types to other data types. And this is going to be useful when we use a lot of the input function. So that was all about the basic data types in Python. 6. Conditional Coding: If Statements: Guys, in today's video, we're going to step into if-statements. Now this is going to take a long time. There's a lot of components to breakdown. So don't worry if this takes too long, you can actually break this video down across two sessions. You know, you can watch half of it in one session and the other half and another session. There are certain times where you want the computer to do something based on a condition. So if something, if a condition matches or doesn't matches, you want a certain code to run, right? You don't want every code to run every single time, right? So the basic format of the Python ifStatement is basically if condition colon, not a semicolon, just a colon. And then you go to the next line and indent, give it some space. Given this antenna is important because this separates it from the if statement and the actual code that has to run and print example. Now this is just an example statement. You can run literally, literally any kind of code in here. And then the thing I want to also introduce is the else statement is when this condition isn't met, it would immediately jump to the code below here. So it would look something like counter example. So if condition is met, then it would print example. If not, then it's going to print counter example. Okay, so let's get a bit more into this condition is always based on operators. Now let me give you a quick lesson on operators as well. So these are some of the most famous comparison operators that you're gonna use throughout the pipeline. P-type a equals equals b. This will check if a equals B, let's say honestly a and b are different. So this is not true, right? So what, in other words, what this means is false, right? Now, if you do a equals a, then obviously this is true and it will return true. Every one of these comparison operator is resulting in either true or false, right? Because if we go back to the if statement, the condition here, it can only be a Boolean value, right? It can't be if five, right? I mean, if you're trying to do at five, you have to do something like if a equals equals five in order to produce a Boolean value if it's true or not, right? So let's keep going down the list here. This is greater than or equal to, this is less than or equal to, this is greater than, less than, and this is not equal. So if a doesn't equal a, this would obviously false right? Spot, right? Now be a dozen equals. This is a true statement. A does not equal b, right? So this would return true. This is how you would write something not equals. There is also three combination statement. These are not comparison operators, but three, I guess, modifiers that can help you write more conditions, right? All the time your code relies on just one condition. It relies on multiple conditions. Let's say we want to find everyone who's 13 and is a boy, right? So you would now start using add or all right, because there are multiple conditions that have to be figured out. Now, what is the difference between add an OR this goes, this is English language. And it's basically both, both conditions have to be true, to be true and or is one of the conditions just can be true and then it will result in true, right? In other words, if 13 or older. Ok, but let's, let's use actual type, age equals 13 and bender equals male, right? This would be a condition that you would write using. And now let's say we're looking for a person that's either 13 or a mail, so it doesn't matter. They don't have to be 13. And the boy, they just can be 13. That can be a 13-year-old girl or a 13-year-old boy? Or just a boy or just a 13-year-old, right? So in that case, rather than using N, you would use or that's the whole point of the AND, and OR sting. And if you guys look at this table right here, it just clearly shows you the different cases. Let's say there are two conditions, a and B, and a and B are both true, then obviously a and B is true and a or B is true too. If both of them are false, a and B is false, and RB is false. If one of them is true, then obviously in both cases of a and B, they're going to be false, but they're gonna be true for both a or b, right? Because in ARB, only one of them has to be true. So let's go back to the if statements. So in this condition right here, you don't have to separate it with a parenthesis or anything like that. It can just be the statement. You are going to use these comparison operators to produce a Boolean value, right? So, like I said, again, you're only putting Boolean values here if true, right? If false, right, because that's how the computer logic works. Okay? Now, the thing I also want to talk about lift statements now, elif statements are basically when there are different cases, right? Let's say to every three-year-old in the party, you wanna give them a goody bag until every 4-year-old, you wanna give them a toy. Okay? So in this case, you would use something like if aij equal four, L, if age equals three, because there are different there's different statements that you want to run for different ages. That is when we use l If this is also shorten version of else, if that makes it L if it's just like another, if you want to do a case-by-case if statements in Python. All right, so for the first chance we're going to ask you guys to do a really simple challenge because there are a lot of information and shoe. So the first challenge, we're going to first ask the user for their age and then initialize the variable age to that value. Now when you as Uses, I've been talking about, I didn't mention this, but when you use the input function, remember, just put a quick hint parentheses around the whole thing. What this does is basically the input default. Data type is a string, but we want it in a integer, right? Like number. So not to use input, but use this function. And you can just put, we're supposed to put an input just in here, but just remember to make sure you add this int parenthesis, the whole thing, just a, what this does. It basically converts whatever its value inside the parenthesis into an integer type. So that's all it does. Then we're going to ask, we're gonna make a program that determines if the ages above 16, it's going to print here is your driver's license. If not, it's going to print come back soon. Alright, so try that out, pause the video and then a return for the solution. So first we want to have the variable age and, and we have to remember use the int function to change it into an integer. And then as the input to ask the question, how far are you, right? Then we're going to determine if the ages above 16. Right? That's a way of saying If the ages of 16. So it can't be 16, right? When I add a colon right here and then have the print statement. Print here is the Earth drivers, lice Prince. Now, we're going to indent that because there is a false statement. So if that's not true and you want to have an else statement, right? And now we're going to print conducting. So this is what your code is gonna look like. So let's run this real quick. It's gonna ask me how am I? Let's do a value less than 16 first. 15, Come back soon, okay? Now let's do a value that is 16, right? So this should still print convection because it's not above 16. There we go. Come back soon. Now, if we run a longer time to do an age above 1617, we would get here is your driver's license. So that is how you do this challenge. And that is how you use if statements. 7. Iteration Part 1: Functions: I guess now going to talk about functions. You've worked with functions before actually like the input function, the string to type converter functions. Always mentioned, mentioned functions, but let's get into in detail what exactly a function is. So you understand function is a, something that for you if you put something between the parenthesis and it will do something for you. Now let's dive deep into what it actually is. I have two blocks of code, like life could not Python code, but like instructions, right? In your opinion, what looks more clear, move had up, move her down, move head up, move her down or not twenties right there. Different set of instructions but they still perform the same, right? Or to me, or at least to me, the non twice looks much more clearer and easier to understand for a code. And when you guys write big blocks of code later, it's really important that you maintain this clarity and brevity throughout your entire code, right? That is why reliant on functions. Functions aim to clear up some of these long codes by representing a large long code into a function. We're able to call that function over repetitively, not having to write that long block of code every single time we want to use array. So let's get into how we create these kinda function. We worked with functions, but in fact, you can actually create your own functions in Python. So make a function, you're gonna have to put DEF and a space and the name of your function. So when you call it later, what are you going to refer to it as? And for this case, I'm making a sample sum function called print hello world, hello world. And what it does is it prints Hello world and you want to have two parenthesis and a space and then a colon. Now under the colon, you'll want to go into that and you can add variables in this function. Now this variable isn't accessible outside your function. So let's say I make a variable called phrase and assign it to a string called Hello World, I can't access phrase outside my function. This variable only applies to this function right here. Now, I'm just getting the phrase and you can actually call other functions inside your functions like the print function. So obviously, the goal of this function is to print Hello world right? Now, when it comes to creating a function name, you want to focus on short but accurate. Does that make sense? You want it to be short, right? You don't want it to be a two long word. And the reason why we wanted shortage, because remember it's all about making it simpler, right? But we don't want to be too vague rate, so rather than having helloworld function, something like print hello world, right? And the reason why I have this underscore here is you can't have spaces between when you name your functions, you know, so a lot of the times people just resort to the underscore to represent a space. So remember, short but accurate is what we want to remember when it comes to creating functions. Now let's jump into parameters. Now. What are parameters? Parameters are basically when a function depends on a situation, right? So let's see any creator function called find age. Right? Now, not everyone's ages are in the same way. I mean, some people have the same age, but obviously some people at different ages rate. And that is determined based on your birthday, right? So let's look at this simple code here. Obviously this isn't Python, this is like a logic. A logic function. So the way to calculate ages going at the current time and subtracting your birthday and seeing the difference in the ears right? Now there's birthday is different per person or per situation when a value in a code depends on a certain situation, that's when you use parameters. Now, the weight you initiate parameters is inside the parenthesis when you make the function, and you can refer this to as a variable. Now, when you use your code, you would have to give an actual value in here. So let's say my birthday is December 20th, 26 to 2009. I would put some sort of maybe a string and integer, but some kind of value inside here. When the code, when the code, when the function runs, it can refer to the birthday, as, you know, December 2062 thousand, right? So that is why we use parameters. Sometimes functions depend on situation, values depend on situation. That's why we use parameters. Now, I also want to tell about this returned picture here. Return basically executes a function. It's like the last line that a function really has. Let's say I have the age and then I just did currentTime. I'm subtracting my birthday and it's an integer value. So whenever we turn age, this function not only executes, but also represents this integer value, in this case age, right? So in other words, found a tray and then have the client age function. And let's say, let's just use the same example right? Now. If I run this, the reason why I can save, save this function has available because that variable returns an integer, right? So found age will carry or store a integer. So that is a function of return to not only execute the function, but to have the function represents a certain data type and the data with it, right? This is all you have to do. Then you can name it whatever you want. This parameter. Once again, when it goes parameters, you want to make it short but accurate. Okay, I'm gonna give you guys a really easy challenge. So we're going to create a function and you can name it, just multiply, underscore ten, ok? Now, this function is supposed to multiply ten to a number that is taken as a parameter x. Okay? So you want to have a parameter x and it's just going to aim to multiply ten to it. Now, the challenge here, that the challenge here is you can't use the plus or multiply operator. So try creating this function without using the plus or multiply operator. And lastly, I want you guys to print the number so that we can see the proof of the actual thing. Now I started, started with a hint. You guys can use this model, right? Multiply ten with the x as a predator and obviously bought on the bottom, you guys have to figure it out. And the last thing I wanted to give you, the last one I want to give you guys is for multiplying ten without using the plus or Multiply Operator. Go back to the last video and look at how I was able to fake multiplying ten using strings right? Before you guys go off and try the challenge, I want you to remember that once you make a function, it doesn't run unless you call the function, and we're going to call the function, all you have to do is just get to a new line. And without the death, just write the name of your function, right? And then rather than x, right, you would put an interger here, let's say ten, and then you would just have to run it. Now obviously this function is going to return a value and in order to print it, you would have to print this. You will have to put the print function over the function so that it can print the number, right? So on trial to challenge you as 1A solution, connect to the video. Alright guys, Hope you guys were able to figure that out. So first we're gonna start with a death function and then where it name it, multiply. And once I got molecule that phi and underscore ten, right? About we want an x as a parameter, so we're going to put x here. Now what we wanna do is we don't want to use them multiply operator, so we have to change it into a string to add zeros at the end. So it looks like we're multiplying ten. I'll make a very old professors x turned to string, right? Because we first have to make accent to a string and then just use the string function and put x in it. Right? Now, I have to use external string and add zeros at the end, right? So the return is, I'll just do something like number that returns equals x, x turned to string plus a 0 string, right? Because that's gonna mimic as I would multiply ten. And then lastly on our returns, this number, right? Because remember that returns because then we will have to, we're going to be able to print it right now. Is it a numbered? Not really because it's a string, but when we printed, it's going to look exactly like a number. So once we created the function, we have to print them Valley breaks. So I would do print. And then how would call the function? Now, I'll do the number 75 just to keep it consistent with the last challenge. And let's see what happens if we run our code. There we go. We have 750. Now intrinsically, this is not a number, this is a string that we just added 0 hover. We're still able to mimic multiply ten by using strings. So hope you guys robots to figure that out. And I'll see you in the next video. 8. Iteration Part 2: Loops: All right, okay, so in this video we're going to be talking about lists and loops. So let's first talk about lists. So what lists are basically what the name suggests. It's a list of data types. And in the lives you can store anything from a list of integers, a list of strings, and on and on and on, right? So take a look over here. So this is an example list where I have all the integers that start from one and ends at six. Okay, that is an example of a list. And I can even put names in here. I can put whatever data type I want it to be. And you can index through lists or indexing a list is finding a certain value inside a list to using the position value. So I want to explain. So remember in Python everything starts with 0, right? So although it starts with number one and it's the first position in the list. We count it as a 0 with position of the list. So this is actually the 0th position, the first position, second position, their position, and on and on and on, right? So if we were to find a variable six, right, we want to put example list bracket six. We would put five because that represents six, not six, Because comes it starts counting from 0. So if you want to index a list, you would have to write the name of the variable that you represented as a list and then use a square bracket. And then it will find for the position of the value inside the list. And remember the fifth position is in fact the sixth edition if we start counting from one, okay, so that's what lists are. And we learned about lists because we want to get familiar with for loops. And for loops are a way to trigger repetition in your code, right? So take a look for example. Now, this range function is a function that creates a temporary lists, okay? Now the range function creates a list starting from whatever value you give it on the first parameter, one, right? It's going to start from one, and it's going to stop at one less than whatever number you make it stop that, stop that. In fact, this, this range one to 11 creates a function starting from one and ends at ten. Okay? So make sure that the second parameter is one more than when you actually want to stop that, right? The format is for whatever variable you want to refer to as the repetitive but variable in. And you can put whatever list you want here. It doesn't have to be arranged. You could have made a pre-made list. Range is a good way to make a list that's counting upwards incrementally. And I'm gonna talk about how you can count and a certain number of steps, okay? So for every i in the list between one to ten, it's going to execute this code, right? So the first I is going to be one, and it's gonna take US I equals one as the first time it executes this code, right? So some, we have some on, initiated at 0. So sum is going to equal 0 plus one, right? So sum is now one, right? And it's going to print the sum. And then now that there's no more, this is not a code, so this is separate. So that there's no more code. It's going to go back to the first line, however, because it already did the code for one, it's going to jump one more. And due to, so I0 is going to represent two now. So it'll do the same thing. Sum equals, remember we made it 11 plus two equals three, right? So now sum S3, and then it's going to print three, and it's going to go back and go to the next element. Which is three. And it's going to keep doing that eventually wanted until we get the sum of one to ten, right? So that's what the repetition works. I represents a value that goes through a list and you use i as repetitive element to iterate through your code. So you are going to be more familiar with this once you do the challenge. Okay, before I move on, I want to talk about the range function. Now, in the rank function, you can add a third parameter which shows you the incremented step. Okay, so the difference between range one comma 11 and range one comma 11 common too, is that one common 11 will automatically increment by one. So do 12345678910. However, when you add a to, it will come by two. So rather than being one to differ, it's going to be a set of odd numbers, right? So it's going to start at one and it's going to increment by two and going to three. So 13579, okay, so if that's the, what the third parameter does in a range function, we have another site aspects called While Loops. Now while loops are a condition-based loop. So a for-loop is when you give it a certain range. But while is like, you don't know when it's going to end, but you know, a condition that you wanted to end on, right? So let's look here. So for while loops, for loops you don't have to initiate I or one of the repetitive element is. But for a while loop, you're gonna have to initiate like I equals 0 here. Same thing. We're gonna do the same thing as the for-loop sum equals 0. And this condition is saying, while the repetitive element is less than ten, we're going to continuously repeat through this block, this block of indented code. So let me walk you through it. So i is first of all, zeros, right? So while 0 is less than ten, is that true? Yes, 0 is less than ten. So it's going to go to this function is 0 equals 0 plus 0, right? Right. So sum is still 0. Unlike for loops, it doesn't know how to increment by itself. So I will do something like at the end, once you've finished before it goes back to the while loop, then we want to increment it. So i equals i plus one. So now i is going to be one when it goes to the second time. Is one less than ten? Yes. And one plus some used to be 0 plus one equals one, right? Now it's going to print one and then it's going to add another one to i. So that becomes to see how it's incremented now. So every time it's going to be added is going to be added one more value so that it can incrementally increase. Now, there is a point that is code when I reaches the number ten, right? When ten is ten, less than ten, no, ten is equal or less than ten, right? So it's not less than ten. So once this condition doesn't mean it's going to exit out. So this while loop is done as soon as this condition is met. Okay? So once we, once we hit i equals 345678910, once it gets to ten, it's no longer true. And it's gonna get out of the while loop and stop the repetition. And that's how while loops are different from for-loops. And the situation where you would use for loops is when you kind of know the range, when you want to know, when you kinda know when starting I went to end. And while loops are for, you don't know when it's going to add, but you know a condition that you wanted to end on, right? So that's when you use while loops. So for this loop challenge and went to do a very simple challenge. So I'm going to ask you to print every even number between 1100, including 100 of sorry, this is 11000. It's going to include 100 using the for loops method. Okay, so the first one, and you've got to use the for loops. And the second one you are print every odd number between 1100, including one and would include 100 obviously, using the while loops matter, okay, so try that out and come back to me for the solution. It's OK. First, start with a four, right? Now, breeze, I usually end range. Now this is the important part you want to start a to read because that's the first even number. So we're going to put two and then we know that it has to include 100, right? So we want to start one more of them. However, it's countered by even numbers, so we're going to have to include 102, okay? So that's the tricky part here. You are not including 102. And then we want to increment it by every even number, which is another to write for the increment upset and then a colon and that, and that is face. I think that's central for the 11. We're going to have to initiate a repetitive element. Let's just call it J, OK? And then we're gonna use while j is less than 100, we're going to print print kit. Now these are the incremental steps that are important. So first, we're going to have to add two to every graph, to add two to j every single time, right? So if i equals j to right. Now the important thing here is it has to start at one non-zero, right? Because we're going from one to 100 and this is what your code would look like. So let's try running this. Ok, so let's scroll through this. There's a bunch of numbers. Let's see if we got we want it. So okay, from 2468, right? It's printing every even number until it stops at 100, right? So let's see if we're a 100 and included, and there we go. So 100 is printed. And then it's gonna do every odd number between one to 100, which will, which means it's going to start at one and end at 99. So let's scroll down and see if it has a 99. And there we go. So these are the ways to use for loops and while loops to help you do repetitive tasks in Python.