 I'll just start whenever the screen pops up and I meet myself because okay, all right, we are live. Hello, everyone. And welcome back to our introduction to Python course. This is a recap of unit three input and I told I told Dr. Jack that I would say input and output because I can't not say them together, but that is not the name of this good is the is input and flow control statements as part of Sailor Academy's CS 105. This is again the recap of unit two. If you haven't started the course you can go to sailor.org and find the course. You can also, if you haven't caught up to unit three we've done recaps of unit one and unit two, which you can find on this YouTube channel. All of the links should be in the description below. If not, I'm going to put them in the chat right now once I hand it over and of course, feel free if you guys want to have a conversation outside of this chat or outside of the comments you can go to the discourse forums at discourse.sailor.org. And I think that's everything and if I forgot it I'll bring something up later but right now I'll hand it off to Dr. Eric Zach to take it away. Fantastic. Thanks so much. Thank you. Nice to see everybody this week and just want to quickly briefly talk about the input statement I'll give it I will probably give it about, you know, one minute or so, just because it's important to understand as it says here in the course itself that when you when you are expecting input. The input instruction is going to return a variable of type str and that's surprising to some people who first start out. Because what you sometimes what you sometimes you want a string sometimes you want characters, you know, sometimes you want to type in somebody's name, you know, or, you know, the course they're taking or something like that and that that will require text but oftentimes when you're starting out with data from the keyboard. You want numbers you want you want to calculate something so when you when you want to calculate something you have to take the intentional step of converting the string to either an integer or a variable of type float. So that goes in the course down around the second paragraph that kind of tell you or teach you or show you what it takes to, you know, convert to an integer convert to a float not hard you just drop the input statement into a float instruction with two parentheses around it and that's the syntax for doing that and then you would convert it to a floating point value. So just, you know, if you have any questions about that you can raise it otherwise, you know, I think it's very, it's very straightforward to do. But sometimes, when people are first starting out they have to be reminded, you know, they have to be reminded of how to make that conversion because it's an intentional conversion again, you know, with regard to data types. You're starting out, you know, learning a computing language and you have to start, you know, kind of fielding all these different types of data invocations you know data type invocations you know you can get a little confusing but it's just because the computer represents data in different ways you're really, you're helping the computer out quite a bit when you're, when you're invoking a certain data type so anyway that's there. And I think that the time is probably most useful he spent today is is where it could be spent is on conditional statements and and on loops and whenever I teach and this is also in the course as well whenever I whenever I start to teach about conditional statements. I try and show flow charts and and flow charts again are, you know, sort of like at the at the introductory level. You know, sort of a pictorial representation of what your computer program is supposed to be doing and even these days people don't use them that much but if you start to do this for a living. And you know you find yourself scribbling stuff on the back of an envelope when you're thinking out an algorithm trying to solve a problem. And you know you start scribbling down these little pictures of what the flow of the computer program is supposed to be doing. They can be, you know, quite useful now I'm not even an expert flow chart maker I mean if you go into the ANSI standard and you have a real flow chart people they're, they're very, you know very territorial about their about the pictures that they make and the, you know, various diagrams and what they, you know the tools that they used to build diagrams and so what I want you to understand is how to sort of draw some people are left brain some people are right brain some people are more analytical some people are more, you know, artistic and picture represented and you know it's it's good to have both sides good to have this coding side and it's good to have the picture side to be able to, you know, arrive at a solution to, you know, if you're writing a program or a solution to a problem. So, um, and and and that's the way it is so so really when I write flow charts is really only three tools that I use I use a diamond I use a box and I use a circle. And the circles are for start and stop if I wanted to actually make it clear that the program was starting someplace or stopping somewhere else in the control flow. But then the diamonds and the boxes are important to me because the boxes represent, you know, stuff that needs to be computed oops like this here we go. So here's a flow truck so the boxes represent something that needs to be computed, and, and the diamonds represent decisions and, and the decisions are what make a computer a computer if you really really really really really really ever get into the theory of computation if you really ever dig deep enough what you'll find is that unless you have those little diamonds in your program. All you have is a calculator all we've done to this point you know with operators and, and you know relational operate. I've taught you how to build a calculator basically I've taught you the syntax to do what you could do by pressing a button, a button, a bunch of buttons on a on a machine, but we want to do more than that what we want is an automatic computing machine and ACM something, or what some people refer to as a Turing machine. A Turing machine is something if anything is if anything in the universe is computable a Turing machine can compute it and one of the fundamental components of a Turing machine is the ability to make decisions. And once you have a system that can make decisions between one potentiality and another potentiality, then you have a computer you really have a true computing machine at that point. Before that you don't and so these died the diamond that you see here is very very important to to to developing or designing a computer language and all computer languages. If they claim to be a computer language have if have some form of if statement give you some capacity to compute conditions and make decisions based upon those conditions and in Python their if statements, and they're also if else statements and or if else else if or ellip statements you just, you can create a whole whole stream of conditions that you can sort of implement within a computer program so this little diamond is incredibly important because it's like your program to the right you can see whatever's running sequentially instruction instruction instruction dot dot dot dot dot dot dot dot and then you bump into this if statement and then the if statement and again at the introductory level. This sometimes blows people's minds away it's very simple it's very but it's very important is that the if statement is going to decide between one potentiality and another potentiality, and it's not going to execute both of those potentialities that is going to be left alone one will not be executed it is conceivable that you could write a program where certain sections of your program where there are lines of code may never be executed they may be sitting in your program and because of some condition that the computer plops over the jumps over those branches over those instructions and does something different based upon a decision that was made and it's very important to understand. Some students like I said when they first it up like wait I got these instructions here but they're not going to be executed it's like whoa wait a second yeah well it's true. And so in this case that's what the diamond that's the picture that's what the picture is telling you is if some condition turns out to be false. Then you're going to continue program execution program control is going to bypass this other group of Python commands they will not be executed. Or if the condition is true in this case, then then they will be executed again this this this flowchart is in your is in the course it should be there. And then, of course, maybe it turns out that that you want to not just jump over a bunch of instructions but you want to execute two sets of instructions, if this is true do this, otherwise do something else. Well, in the otherwise case you've got a whole section of code that's the indented Python commands group to now. And whenever you're the syntax hopefully you understand at this point if not we'll go over this in a second but I'm just giving an overview. Is that is that when you have the if condition the syntax is to end whatever that condition is with a colon, and then you indent everything that you want to do if the condition is true. Otherwise, if the condition is false you have another set of indented instructions, and it may just be one, it may be one instruction and and there's a utility the else part of the if is is going to is going to execute those other instructions so once again, you've got two sets of instructions only one of which is going to be executed the other wound I mean you've got a binary decision and in general by me it's true or false you're going to do one thing or the other thing you're not going to do both of them. You've got two codes sitting here again that that may not be executed and then, of course, you know when you start to write more complex programs. Well then, you know you could have a whole sequence of conditions that you need to, you know, like if you build a menu, right you're going to build a menu and someone's going to enter a number, you know you have like 10 choices, you know, and each, each of those choices has to be available to you're only going to pick one, but there could be 10 sitting in your code. So you write a menu if one do this if to do that if three do that if the user enters 10 do this. So this is what the if elfs are for is because it enables you to write a long sequence of if statements if it's true do this else do this else do that else do this. Excuse me. Um, so other languages, and this is why like Python so much because it's so minimal it just Python seems to have looked at other language and just thought, you know why are you doing this there's just so much there there's too much there. I'm a minimalist you know and so there are there are things about Python that are very minimal. In other languages, you'll see something like for example a switch statement, and a switch statement basically is like an if else kind of a statement except it uses it assumes that you've got some condition like a number, and then allows you to numerically outline each one of those Python has no switch statement so if you programmed another languages I don't want to burst your bubble I know some people love the switch statement I'm not a fan of the switch statement I'm a minimal minimalist because I know underneath the hood they're just a bunch of if else is so why not just write the if else is that's kind of how I think but you know other people like the elegance and the simplicity of switches so just a if you're coming from that background. Little full disclosure if you anyway let's pop over to the to the replete window and oops I didn't mean to do that. And so, you know we'll set a equal to 234 not a very exciting number, but if a is equal and this is where the relational statements come in, by the way, when when you're when you're testing if statements. You have a binary condition so so if you're basically it's a Boolean condition but you're writing if conditions with the intent, either intentionally or not intentionally I mean again some people take a little while to get this you know, but the but whatever gets evaluated in the if statement is going to be a Boolean statement, and it's going to be evaluated to either true or false. So you could even have mathematical, you could even have mathematical statements you know you could you could have arithmetic statements in your if statement but at the end of the day, the way the if works is it's going to. It's going to evaluate a Boolean statement so here's an example of an if else I just want to make sure we've all got the syntax. So very straightforward you've got the colon, remember, and I just want to say this I always. This is cautionary note, you know in terms of what it means to program the 50% is learning the syntax you've got to get the syntax right because I said so before every every computer language. It has some form of a conditional test of some kind and oftentimes it's like an if statement of some kind. And so it's important to learn the syntax for each language it's a little bit different the other differences. And if you start to program, you have to program like five different language you start to mix them all together which is always fun but but I'm just so both Python you got to have the condition, and then you got to end that statement with a colon and a syntax in that this a I know just like we did, we've done and we will be doing this is very normal. This is going to be very consistent and you might as well just emotionally prepare yourself for the fact that this colon is going to pop up all the time now. Okay, for the rest of the course because that's how Python understands things not just if statements but they'll be a whole host of other, you know, utilities and tools that we learn that are going to require that colon. So much of that anything that's indented is is considered to be part of the is considered to be part of the if clause and that's what's going to get executed so that's all that's how it works. And then if I change a to 235 then of course we're going to execute the other potentiality. So, again, it's not, it's not difficult is a very simple concept. But when students first start out, it's a little strange that they're going to have X commands in their program that that won't that can potentially not be executed. And that's just the way it is, you know, that's how computers work, the ability of a computer to make decisions is fundamental to computation. And again, you don't have a computer without them. So you could. So coming back over here. Really, this is this is the most important when you, when you concept is when you when you start to write a series of if else is on that there's an ordering. Okay, pay close attention to this there's an ordering to the decision making process. Okay. The decision making process is it kind of goes where the if is checked first and then the next LF and then sequentially the next LF and then sequentially the next LF. Okay. What do I mean by that well. If we do something like this let's say LF L if I have another condition here maybe if a is equal to 234. No, I don't know why you might want to do this but I'm just trying to point out that that the decision making process takes place sequentially and then only one of those potentialities is going to be executed. You know, LF, you know a equal to whatever. So then do this, oopsie daisy LF. That's great. There we go. I don't need that. And, and so, you know, obviously, the way that I set things up so far is that is that a is an equal and maybe I'll throw an else in here as well for the heck of it. Oops. Something like this. So, so here, just, you know, just to kind of give a tangible, not doing anything really exciting. This is not the most exciting program in the world. But if I, oopsie, and I got to indent that guy. So I've got all these indentations now. And within each indentation that that defines the branch of the if statement or the LF statement that will be executed under the circumstance where the condition is true. Okay. And notice I've got two conditions that are exactly the same here. Okay, and if this condition is true we do this if this condition is true we do that. And again, you know, you got to go back to this picture to make sure you understand that this is a sequential process and, and when the decision is made you're done. Okay, it's bye bye you don't even pay attention to the rest of those if LFs. Okay, you're gone, you're on to the next thing and that's what this whole. The left brain picture and then the right brain side of this is all the code over here so once you execute a potentiality, then you're down, then you jump all you branch or you jump, depending on what's happening underneath the hood and what the syntax is if you think of branching or jumping you jump to another place in your code, and effectively you disregard all this other stuff. I mean that's why you're writing the if in the first place so just want to make sure we get that you know so if we were to analyze. What happens here in the extreme case where I test two conditions simultaneously, then you know we want to see what happens. Obviously the first condition is printed out and then the second one is disregarded we never pay attention to it so even though a is true. So the fact that we executed the first if we jump, you know, all the way down here and you know we might say, you know by by or something like this. And, and so we, we jump down to the end of the, down to the end of the if statement, if I can get this thing if I can type right this morning. So, so all those other potentialities in some sense are disregarding because you satisfied the first one sequentially, and it could be that another condition is actually true. Now that that's, you know, that's bad code, as far as I'm concerned but but I'm just trying to highlight the point that you get an if statement with like a whole bunch of conditions that are the same that just doesn't, you know, there aren't many places where one might want to but I'm trying to highlight the fact, you know, highlight this picture where once that chunk of code is executed you go into that particular branch of the if statement and then you're done and then you sequentially go on to the rest of your program. So that's that's program control that's called program control because you're controlling, you know, at the low level really you know the same that you're you're causing the central processing units to start you're jumping around you're causing you're causing the CPUs to think Oh, I've got to go here and then I've got to go there and then I've got to jump over here and when you start doing that that's when you're really computing that's when you're actually doing something interesting. So, so hopefully everyone gets that that's that's sort of the first part well there's the input and then there's the first part of unit three. And I'm happy to stop for any questions with, you know, if LFs if anyone has anything so there's syntactical issues and then there's implementation issues understanding how it works. And then, and then as you start to use these this is where you start to learn to program we're not really programming in some sense because we're not solving any problems we're not writing any problems but but you got to know the syntax for implementing this type of a structure this is, this is probably one of the most important structure I can't overemphasize it it's like you don't have a computer without this so happy to take questions at this time. Because there aren't any. Well, I'll tell you right now. I think the first thing everyone should do when this stream is over is look up what a turn machine looks like. Because it's basically looks like a cassette tape or a videotape, but the size of a table and it's pretty crazy looking. But yeah, the question that I think was posed maybe a couple weeks ago but since I don't remember the answer. And I'll wait for the chat to catch up on the, the double equals sign on the if statements. So, great question, the, and this is really this, this is why unit three comes after unit two is in unit in unit two we learned about operators and they were arithmetic operators, and then there were an unit one we learned about the assignment statement by the way also so you didn't want to talks about the assignment statement for the equal sign which, again, it's kind of like you're thinking of taking whatever's on the right side of the equal sign then plopping it into whatever's on the left side of the equal sign, I guess you're looking and then, and then we learned about operators after that and we talked about relational and logical operators which are only allowed to give answers that are bullying that are binary in their nature which are true or false. And so this is again one of the, and I think even, you know even one professional I know I've done it you know professional programmers even do this as well sometimes when they're not when they're not thinking you know they're just to sort of doing stuff automatically you know like an automaton so here is the, here's the assignment statement here the equal sign is being used to assign the variable a the number 234. So there was on the right side is being transferred into that variable on the left side so we know after that, after that instruction executes that that the variable a contains the number 234. Okay, until it gets changed later on till we do something else with it but that's what it's been. That's what it's currently been assigned the value of 234. Now we come down to the if statement. We talked about relational operators and just to review unit to the relational operators were greater than greater than or equal to less than less than or equal to and the double equal sign means equality. So it doesn't mean you're assigning a valley value means you're testing something you're saying, you know, a equals be and when when you do something like this the only possible answers, just like for all the relational operators is either true or false if a equals if you get a Boolean true and in Python that's actually the word true. That's a reserved word and then if a does not equal be you get a Boolean false, and that's really what the goal of the, of the if statement is you're trying to figure out basically if the condition is true or false, because the if is the if is only capable of evaluating Boolean expressions it's only it's it's only going to execute based upon whether something is true, or a false, that's it that's all it looks for numerical values, although you could drop numerical values into an if statement but you got to know what you're doing you got to really, you know, because all languages are a little bit different when it comes to deciding, making decisions on on on numerical values other on numerical values so so right now we'll just keep it in the Boolean space and so this this this condition is only going to is going to evaluate to either true or false if if a is equal to 234 well then we're going to do this and and and and and and a is assigned the value this is a test and all it is is a test you're not you're not assigning anything so the value down here is of a is in fact it's still going to be a nothing nothing changed nothing got reassigned the double equal sign is just a Boolean test okay and and that's all that's all there is to that because relational operators the reason that we introduced them in unit two is because we're planning on using them both for if statements and the next subject we're going to get to what you're going to be loops and so so if statements can only make binary decisions and those binaries decisions usually usually usually usually, you know, 94.3% of the time are based upon the outcome of a mixture of relational and logical statements you know so we could do something like this we could say, you know be is equal to 4567 and then we could do this we could mix when we can say and you know be less than 1000 let's say okay. So, so if you if you have now this condition we talked last week this is why it's so important to understand those relational and logical operators is if a is actually equal to 234 and be happens to be less than 1000. You know then we're going to accept so we don't execute that condition why because be clearly is not less than 1000 but we make it less than, let's say 10,000 and then that would be true. And so now we go ahead and execute this this instruction so so the whole point of introducing the logical and relational operators is that so when you're comfortable with them. Now we can start to apply them with if else an L if statements because we're actually testing those those logical conditions so it has nothing to do with assignment it has nothing to do with the equal sign. It has nothing to do with the assignment operator. And that's that's kind of the flow of the course unit one we talked about the assignment operator because you've got to learn how to assign variables. Well, the kind of variables that are either string float or integer so far. And, and so that's what we start with so you learned how to how you learned about data types and the assignment statement. Then we go into unit two, where we say okay well now you know how to assign variables what do we do with them well one thing you do with them is operate the operate on them with arithmetic up you can add subtract multiply divide, you know take power is integer division those sorts of things. And then the next thing that you want to know we wanted to prepare you for was this unit where relational logical operators that the major major place where they're used is in if else an LF statements because you're trying to ascertain some logical state based upon. You know the condition of a set of variables. So very the double equals is is infinitely different than the than the assignment statement because it is intended to evaluate to a Boolean true or a Boolean false. Hope that answers the question. I'm sure that over answers the question. So we did get one quite what we got a question while while you're doing that and it's basically it's about the else verse L L if statement statement meanings like. Well, again, the best thing to do is to have this picture in your head, because the LF really the LF is just means you're not done testing conditions it means you've got like a host of conditions that you want to test and so LF is is is shorthand for else if most languages have else if that's usually any kind of Python for whatever reasons. Probably, you know, happened so long ago, but you know the the condition else if was it's like a contraction for LF. So, so it's just your program could potentially have a number of conditions that you're trying to test so it could be like if else if this is true do this else if this is true do this else if this is true do this you know. Okay, so this this series of commands you can put as many LFs as you want and and you can create a series of conditions a series of test conditions and test each one of them and the LF would be used to do that and once again. The structure or the code structures that you would use is that if this is if something is true then execute this group of instructions else, if this is true, then execute this and then the else is kind of like, and you don't always need one. You know, but but it's like cleanup if it turns out that you, you kind of left out any conditions that weren't contained and you want to your writing code. It depends on you addressing anything outside of the set of conditions you've already addressed then everything gets sort of plopped into the else condition basically you know. So, you know, if you, and so the picture once again is if the if only one of those potentialities is going to execute so. But if a is equal to 23434 else if you know a is greater than 242 34 do this and else if it you know that a is less than 234 345 and, you know, a is greater than one or something like this and then else everything else. So, you know, if we, if we happen to make a, you know, negative one or something like this, you know, then, then you wouldn't execute this because it's not equal to 234. It's not, it's not greater than two, it's not less than 345 and greater than one so I don't need to stay to condition I'm just trying to clean up things so that I if I left anything out. That's one way you know you can you can think about it I wouldn't program that way you want to have every you want to have a flowchart that kind of defines, you know, it depends if you're doing it for fun know but if you're, you know, designing a grid for a telephone system you probably want to have that else in there just in case so, you know, and people have it and so whole power systems have gone down because of that, unfortunately so. So the else is kind of like the is like the cleanup for, and you know any conditions that that you may have left out by defining them with bullying expressions I hope that answers the question. I don't want to give you, you know, a big head or any hubris or anything but we I can't confirm that the person that asks this question says that. Thank you and they now understand the difference so you did a good job explaining. Okay, so let's let's move on now if there are no questions about conditionals, because again, you know it's something that you want to get really really good at it's something that I have found personally just from you know teaching this stuff. At least for the last few days that there sometimes students come through the conditional unit on the other side of it not fully embracing and and so I really like I said I do everything I can to reach the left brain people and the right brain people with either a picture of the code. Everybody is like a million percent clear it's not difficult but if you don't know it you really can't program you know you don't you're not. You're not able to define logically define sets of conditions with these combinations of relational and logical operators and that would be a shame like I want everybody. It's such an important tool, and I just want you to know it inside and out that's all. Alright, I'm on to loops, and I'm gonna we're going to play a game. And the game is I want to count. I'll start counting at zero let's say and I'll add and well I'm going to count by ones and I'm going to do this again and keep on doing that I'm going to keep on adding one to my eye. So I'm just adding one to I and one to make let's make believe that I'll stop here just for a heck of it and I got a little syntax error here so we got to fix that. Let's make believe that I want to print the value here print I. So like something like oops man stick there. That's replete. Okay, I blame replete I blame sometimes see these editors they'll make decisions for you. And I don't want to do that. Okay, well I did anyway. There you go. Alright, so so far I've counted the six but let's make believe that I wanted to write a program. So that counts to, for instance, 100 million, and I don't think we have time for that so maybe my next week when we come back I'll be done with this program, because it's going to take a while to do that. And so on and on, you know, when it comes to the concept of loops, and that's what you know three is also about. Again for the just going back to a Turing machine and and the concept of doing something over and over again and the program construct the syntax for writing what's called a Luke's you're planning on writing a program and you know you're going to do something over and over and over again similar operations and and make believe you wanted and it wouldn't be unthinkable actually it's normal to have to do something you know 100 million times or a billion times you know using computation. And what do you do well you could write out 100 million statements or a billion statements but those programs would get very long and so for the theory of if you want to be really theoretical about it and really press the issue to a purest theoretical computer you know it could be argued that you don't need syntax that would make it more compact to write something called a loop which is something you do over and over again, but I'll tell you something it sure is convenient. And, and, and that's really where it come where loops come from is is the convenience and the importance of making compact programs. So, when we talk about loops, you know we talk about things like a for loop, for instance, and the for loop is basically something that try to try to make decisions for me here again, I love you know I love Python and then you can hate hate it as well so it's. But when you count when you're going to count. Okay, so the for loop is basically something that gives you the ability to count. And if you want to count, because you're planning on do something 100 million times you, you kind of have to define three things either implicitly or explicitly you've got to, you've got to tell where to begin counting. Where to stop counting and what your increment or your step is going to be, because I could have just as easy as if I if I walked up to you on the street and said start counting. And you started counting at the number five and started counting by twos you would have satisfied my, my command to start counting I didn't tell you where to start and I didn't tell you where the increment was and I didn't tell you where to stop. But for loops need need those either implicitly or explicitly need those three pieces of information basically for loops count that's all they do. I could say something like this I could say for and you've seen this in the in the course as well I could say something like for I in range, you know, five or something like that. And what the range, it's a function, and we'll get into functions within the next couple of units and it's unit five but I'm going to tell you ahead of time right now. Excuse me that that a function is something that you drop data into and you get an answer from we're going to start writing these ourselves user defined functions but there are functions that you can call and that are built in Python one of them is this range function you drop a number in and what it will do actually it'll create something called an iterator and an iterator when you iterate something means you're going to planning on doing it over and over and over again that's what it that would that's what it means to iterate to iterate means or iterate depending on what part of the globe you've got funny story about going to leave it out I'm not going to go there. Anyway, so it. Well, maybe another day. But when you're iterating you're planning on doing something over and over and over again, and so the range function, you drop a number in and it'll give you an iterator that you can drop into a for loop and the for loop when you drop this five and really honest to goodness knows that you are are planning on on iterating on that variable and and notice I'm dropping the number of five and I'm not telling you where to start, and I'm not telling you where the increment is. Well, the range assumes when you give it a variable and we'll get to all that in a second but right now for the for the introductory phase. So the range five it's going to it's basically going to count increments by one starting at zero to one less it's going to do five things, but it's going to start at zero. So it's going to go zero one two three four because that's five things okay. And notice I haven't told it where to start I haven't told it what the increment is so the range if you don't give it that information it's going to assume that's what you want to do. The variable I, every time you go through this loop it's planning on doing this loop five times notice there's a colon again just like the statement and you've got an indentation so anything inside the indentation is what's going to be done over and over and over again. That the variable I is is a is a bona fide variable to true variable and it's going to change every time I go through this loop and you can use it as such you can, you know, you can, it really is something that's being reassigned. Every time you go through it starts out at zero it's going to go to one it's going to change to two, it's going to get reassigned those values so it's not when it loops it's not going to remember as it's counting. It's going to be three it's not going to remember the number zero anymore. And so, so every time you go through the loop each time you do it. This is basically doing what I was trying to do before, which is I plus equals one that's really what's happening. It's it's counting from zero to four it's going by increments now I could tell it where to start I could say something like you know start counting at three and count until 10. I'm giving it the syntax for starting to count that three and going to nine and this is one thing you're going to have to get used to if you if you're not used to it or it's it's just when you start to think in terms of certain computer languages. One of the things that you do for some languages start counting at one some languages start counting at zero, you know, and then when you give it an endpoint some will go to the endpoint, and then others will go to like one before the end point so it's really the is not not count to 10, but it should be something like count while while I is less than 10 that's a good way to think about that's actually how it's encoded, you know, from a low level standpoint so the idea is that you is that you go just whatever you're counting you go one before that value of 10 so 10 won't be included on if you want 10, then you have to remember that you have to go to 11. It goes to 11 I don't know if that's that's a, you know, that's from the ancients, you know, goes to 11 anyway. So, I got it. So, so anyway, and that's counting that's basically but you can do more than loops and just count I mean that I just want to make you aware that that when you're when you're planning on doing a for loop, you're basically planning on doing something over and over and, and, and anything inside the anything it's I was gonna say I was gonna say anything inside the brackets but that's the wrong language see what happens here I'm going losing my mind. Anything that gets indented. Okay, is is going to be executed within that loop. So that's all there is to it now. So there's the starting point there's the stopping point if you want you can create increments as well you can say well count by two is now you know don't count by. So now go 3579 it's not going to go to 11 now because because 11 would be the next number in the sequence but we're not going to 11 we're going to whatever is one before, in terms of the count so really when you use the range function. In disguise, you've got to give it the starting point, the endpoint and the step size. Okay, and if, and that's and by the way that and she should remember that you should remember that because because that's going to be the ordering of the syntax for many things that we do for the rest of this class. It's going to be the start the stop and then the step that's the order some languages aren't like that some want you to give the start and then the step and then the stop so. So again, depending on what background you're coming from in this language it starts stop and then and then step. And if you leave anything, any of them out, then then Python is going to make assumptions for you, because the goal of Python is to always keep running. And so, you know it doesn't you shouldn't have to crash based because you left something out it's just going to it's going to do something for you and so you need to know what those assumptions are. So that's how a for loop works it's just and you can and you can use this value anyway that you want to you know you could say, you could say I star star squared, you know, tell me tell me I squared. And now, when you, you know, say we count to five and we want to know all the squares between. Okay, or you or you can have a number I could set x equal to so watch this in slow motion now so I'll set x equal to one. And then what I'll do and I'll set x equal to one. And then what we'll do a printer again printing these you don't have to print them in loops and oftentimes you don't want to I'm just trying to give you an immediate feedback as to what the loop is doing. And so what I could do is I could, I could set x equal to let's say x times I for instance something like this. And I'm sorry about that maybe I'll set x times x. That's what I'll do. And so what I'm doing here is I am. I will be. Let's say multiplying. And let's do it like this. I'm actually going to play with this a little bit later today too so let's do something like this now set x equal to one in fact. Okay, here we go. And I'm at 1013 so so in this case what I'm going to do is I'm going to print out powers of x I'm raising x, you know, to the power basically because I am, I'm successively multiplying x by the number and in this case x starts out at one. So the loop five times one is five so x gets reassigned and again this is the big deal about loops is that is that when you start to reassign variables. Again, you know, as soon as you kind of know what you're doing the intent maybe the intent is for me to raise, you know, five to the fifth power let's say if I wanted to do that. Again, you can obviously can do that with one instruction so that's not the goal of this example the goal of this example is to show you, you know how a loop could be used to successively compute something in this case we're taking n and multiplying it by itself, you know, over and over and over again so the second time is five squared the third time is five cube five to the fourth five to the fifth power so so this is how you start to use loops as you, as you make computations and then you reassign variables and with with for loops, there's like a predefined accounting process where you know how many times you want to do something and you know where you want to start and you know what you know what the step is. So that's all I want to say about for loops just to kind of, you know, kind of point people in the right direction for the for this unit to make sure you understand what the point of loops are they're very important they're very they're indispensable. Because if you didn't have them like I said computer programs would get unacceptably impractically long you know it'd be too lengthy basically. So I'll give everyone a chance to catch up. What I will say is, I got the spinal tap reference. I was, I was worried because the first thing you're talking about conjunctions and the first thing that came to my mind was school house rock which is considerably older than spinal tap. But don't worry I did my research school house rock started in 1973 spinal tap came came out in 1984. But I'm still, I've still have a younger reverse because the episode grammar that featured conjunction junction wasn't until 1996. Oh my god. I mean it's like these facts here. This is great. It seems like everyone's good so I think we're good to go on if I have something else I'll raise a hand for it. Okay. So the last thing we'll talk about our while loops and again when you go to different languages, you know they give you more constructs for writing loops you know that some languages have do while or do until and, you know, Python is very minimal, in the sense that it just gives you for loops because it's boiled down all computing languages to the concept of either counting or doing something based upon a logical condition. And when you want to write loops that are based upon logical conditions being satisfied that you know for loop wouldn't be possible so the while loop, you know, maybe you'll have a variable like, you know, again, the letter a for nothing better for the loop and and maybe I'll write a while loop with a condition that says while, you know, a is less than 5000, let's say. Again, this will get not the most exciting loop in the world but a loop nonetheless, and then we'll do is we'll say a plus equals. Let's get through this quickly. I don't like that we'll add 402. So, so here what's happening is we're testing a condition using relational operators so while a is less than 5000 we're going to do everything inside the loop. And that says print a so it prints a and then adds 400 to a so it comes 4967, and then, yeah 4967 and then, and then it'll print 4967. It'll add 400 to a and then it'll come back and test that condition again so every time you loop back to the while statement you jump back up here. You test this condition, and you ain't leaving the loop until the condition is satisfied and that could be a great thing or, you know, for people for starting out that could be a really dangerous thing because you could end up like if I never increment. If I if I accidentally never increment a then that we could just this goes on forever. It's called an infinite loop. And those are generally frowned upon in the computer science world because your program isn't stopping. And some famous again theorems about about knowing, can we ever know whether or not a program will actually halt what will ever stop. It's called the halting problem. It's a deep problem because so many other problems in computer science can be mapped on to that problem by itself it's really the question is can you look at a program and know whether or not it's going to stop in general if I showed you any program and obviously this one is fairly straightforward I'm saying, you know, in general it's not possible to do that so that's called the halting problem and then, you know, that it's it's a deep concept because the complexity of problems of problems in computer science sometimes can be transformed or mapped on to that halting problem. And then you can decide whether or not your program, you know, could have a provable solution. And sometimes that's not always the case sadly. And sometimes it is and when it is provable then that's great that everybody's happy and everybody goes and, you know, goes and start sipping penny colladas on a beach somewhere because you solve the problem but sometimes it's not it's not true so in this case the program doesn't end. And, and that's the way it is. So, so you don't want to write starting out you know your goal is not to write programs with infinite loops that that's considered like I said not to be such a great thing. Anyway, so, so that's the while loop and the while loop again the intent of the while loop is to give programs the ability to to iterate based upon logical conditions now you can turn a while loop into, you know, a for loop you could set I equal to zero and then I could say, you know, I, I, you know, plus equals one will increment by one and while I is less than 10, and you know something like this. So usually, it's possible, usually possible should be possible, I mean theoretically possible to turn a, and then I'll put this up here sorry. So, I know, so notice where I put the print statement is very important if I if I printed out after or before I increment that that's a big deal I know that seems like it shouldn't be a big deal but again there are languages that test conditions, either before the loop is executed or after the loop is it is, you know, in some languages this is a big deal. I'm not going to make a big deal out of here because you only got the while but I but I am alerting you if you if you learn other programming languages it is important where you put that, where you put that print statement in the context of like a while versus a do while or do until and all these other constructs that are here. But if you're just using the while loop notice that that if I put the print afterwards I'm going to print the value out and the idea is that the I value goes back and get gets tested against the, against the 10. So I just turned this for this while loop into a for loop. Okay, because this is exactly what I did with the for loop before. And it's not always the case that you can turn a while loop back into a for loop because if you really have real logical conditions. It's a lot easier to express those logical conditions in a while loop. So if you're thinking about something, you know, you know, it probably the place where where this could be useful and I think I do this in the course is is like you're waiting for input from the user, and then the user does something that you don't have the user to do. And so then what you do maybe is you set, you know, flags or something like this is a very, very common use of, of, of while loops you set a flag and you set it equal to false or something like that so I said it I set in flag I'm going to call an input flag I'm running out of time I'm going to take I'll do this in about two seconds so stick with me so while watching a while in flag. Something like this notice I'm not really saying anything important within flag in flag is a Boolean variable to type bull. Okay, so I know it's a Boolean condition and the while loop is kind of like the if statement it's testing Boolean conditions it wants to know if the condition is true or false I apologize I'm going to make this true or otherwise we're never going to. Otherwise we're never going to get anywhere. And so, and then what you'll do is while in flag is true, you might say, you know, Z is equal to input input. There's something where you say type a number, you know, between type of number between, you know, five and 10 or some type of number between, let's say, five and 10 something like this I'm just kind of doing this. So when you do that, you know, if, let's say Z is, you know, less than or equal to 10. And Z is greater than or equal to five. Then set in flag equal, for instance, to false. Okay, and then maybe what you'll do is you'll say else, you know, otherwise print something like, you know, bad input, you see, and this is common use of, you know, and then maybe I'll hear I'll print, like, done, or something like this. So this type of this kind of a loop. Basically it uses in flag to to set a condition, and then you're not leaving this loop until you get the input that you want. Okay, so while while in flag is true you stay here, you know, and you, and you, and you wait and you force the user basically to kind of do what you asked them to do, because that's the way you write software you know you never. You never write software assuming that you just kind of do the right thing that's why that's why you have beta versions and alpha versions because you send it into the public domain to let people try it out and do all the stupid things that anybody could ever do that you never thought of as a programmer, and then you fix them with these kinds of if statements and while loops and so forth. So you could run something like this and maybe I'll type in a number, you know, like 34 it's like hey, I told you enter. You see so what I got here so I've got some kind of a Oh, what did I do here, I did the thing. Right, that said hey don't do this, you got to turn it into an integer right. So, let's turn it into the number three like that, and bad input, and then I'm just, you know, I'll sit here until used to be an AT&T commercial like this with a guy just kept on typing the wrong number for some reason, and he was getting charged for it, you know. And then Saturday Night Live did a skid on it and they were like, you know, we don't care how dumb you are we'll still take your money. So anyway, there's an exception because I hit return but here's the point is that is that you enter this number and you're trying to get the user to enter this value. And so if I if I run this and I actually do give the right value, then, then like six or something like that then you reach done so so this is a case where you do want in some sense an infinite loop until the user gives you the value that that you're asking for. And I forget if I did this example in the course and I but but I probably did because this I want people to know how to use these from a practical standpoint. When it comes to, you know, controlling user input or controlling the conditions within a program. So that you don't you don't leave that loop until that condition is actually satisfied. So that's that's all I have to say today for ifs, for's and while's I'll take any questions to, you know, bring something to close. Well I'll give everyone a chance to answer some stuff I could not that was too quick I couldn't figure find the SNL skit you were looking for. But I did have a question just personally for myself. So when you're programming. Are you just using their regular like quarter keyboard with a numpad on the side or what's your what's your setup when you're when you're doing this stuff. Oh, I'm just using right now I'm just I got my laptop so I'm just doing a query with numbers on the side basically. See, so you do you say you have the numbers on the side you don't have like the top bar that they can't do and I have the top I have numbers on top and I have numbers on the side as well. Okay, what are just padding for time to see if people have questions. Where do you where do you type do you do you tend to like go up top or do you tend to like go down to the right. I tend to go up top. Usually, usually I go up top. Alright, well we padded just enough time we have a question. How would you write a do while statement. Again, the so. So, it all depends with the wild statement. It depends on where you're creating the conditions right. So, so either what when the test occurs you have to it all it all boils down to where that when the test is occurring when you get back to the top of the loop. There's going to be a condition that gets tested so as I was saying before with with something like this let's just go back to this example I said I equal to zero. I say while, you know, I is, you know, less than 10 for instance and then I say I plus equals one and then maybe I'll print. You know, I print I like so. Okay, then, in this case I'm putting the print statement, I'm putting the print statement afterwards. And it seems like an infinite loop. Well, I is less than 10. I forgot that there we go. Well, I equals one. There's a typo right there. Pretty easy. Okay, plus equals one. So, so in this case, you are, you're adding one to I and then you're printing the value out. And so so so the condition is that P name P is not the fun I don't know what's going on there. So, I could also put the print statement in front as well so if I put the print in front, then, then what I'm doing is, I'm adding one, and I'm printing out beforehand and so what's this exception what am I doing here. It says, you got to move the thing over here. P is not defined. I don't know there's no P here so we'll do this and see. Yeah, you got to pee down it. I had my screen thing my zoom screen thing over there. All right. And so, so the, you know anything where you're saying like do on to or while do or whatever it just depends on where you put the condition with respect to where the test is taking place. And so you have to kind of like rearrange your code to to to be aware of the fact that the condition takes is being tested at the at the beginning of the loop. So that's that's how you you deal with all the other, you know, set of, you know, whilst that you could, you could generate with another computing languages. Excellent. I think we're, we're at time here. I'll wait for some stuff to catch up just to make sure but I think that the questions in the chat are now being answered that people are like, I think you're on line 13. But everyone, thank you so much for joining us. Again, this is for Sarah dot orgs introduction to Python course that you can find on Sarah or CS 105. If you'd like to continue the conversation you can always put something down in the comments if you have a question that can't be answered by the community will bring it up next week in in the video. And of course you can also go to this the discourse forums that will help you with that. I'm sure I'm forgetting something. Replet the program being used is in the description below as is the other videos in this course if for some reason you watched all of unit three and hadn't done unit one or two. We have recaps of those and I just like to thank Dr Eric sack again, and I'd like to thank everyone again for joining us. And I'm just going to van for a sec.