Python Masterclass: Learn Python 3 Programming Fast | Lukas Vyhnalek | Skillshare

Python Masterclass: Learn Python 3 Programming Fast

Lukas Vyhnalek, Microsoft Employee, Programming Teacher

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
70 Lessons (5h 59m)
    • 1. Introduction

      2:10
    • 2. Final01 - Install Python

      2:05
    • 3. Final02 - Instal Visual Studio Code Extension

      2:02
    • 4. Final03 - Hello World

      1:51
    • 5. Final04 Variables

      4:32
    • 6. Final05 Starting Of Operations

      7:17
    • 7. Final06 Closer look at numbers

      4:13
    • 8. Final07 Casting(Changing data type)

      5:27
    • 9. Final08 Strings

      10:13
    • 10. Final09 Getting the User Input

      3:19
    • 11. Final10 - First Application!

      5:19
    • 12. Final11 - Advanced Operators

      4:24
    • 13. Final12 - Logical Operators

      6:13
    • 14. Final13 If statement

      5:32
    • 15. Final14 Else If Statement

      5:41
    • 16. Final15 Else statement

      3:59
    • 17. Final16 Practice

      5:09
    • 18. Final17 Lists

      3:36
    • 19. Final18 Tuples

      2:23
    • 20. Final19 Sets

      5:16
    • 21. Final20 Advanced Lists

      5:27
    • 22. Final21 Advanced Tuples

      2:16
    • 23. Final22 Set Operations

      2:48
    • 24. Final23 For Loop

      4:28
    • 25. Final24 Range

      4:27
    • 26. Final25 While

      4:03
    • 27. Final26 Break, Continue

      8:16
    • 28. Final27 Dictionaries

      8:28
    • 29. Final28 Creating New File

      4:12
    • 30. Final29 Write, Append

      4:31
    • 31. Final30 Read File

      2:57
    • 32. Final31 Deleting Files and Directories

      5:00
    • 33. Final32 Try Except Finally

      8:02
    • 34. Final33 Functions

      4:15
    • 35. Final34 Functions 2

      4:17
    • 36. Final35 Recursion

      6:44
    • 37. Final36 Recursion Debugging

      6:26
    • 38. Final38 Lambda Expressions 2

      5:12
    • 39. Final39 Modules

      4:51
    • 40. Final40 Modules 2

      3:04
    • 41. Final46 PIP

      3:08
    • 42. Final41 Class, Atributes, Instances

      2:54
    • 43. Final42 Self, Methods

      6:16
    • 44. Final43 Constructor, Deleting

      4:36
    • 45. Final44 Inheritance

      7:53
    • 46. Final45 Protection

      6:03
    • 47. Final47 Iterators

      7:44
    • 48. Final48 NumberOfOccurrences

      3:13
    • 49. Final49 Reverse String

      3:32
    • 50. Final50 Sum Of List

      2:05
    • 51. Final62 Biggest in List

      3:03
    • 52. Final63 Number of words in String

      4:36
    • 53. Final64 Is Prefix

      4:39
    • 54. Final65 Is sorted

      4:50
    • 55. Final51 Tkinter Window and Label

      5:46
    • 56. Final52 Frames

      7:12
    • 57. Final53 Button

      4:52
    • 58. Final54 Button Clicking Event

      2:25
    • 59. Final55 Entry

      7:47
    • 60. Final56 Grid

      7:08
    • 61. Final57 Menu

      10:19
    • 62. Final66 Canvas, Lines

      5:23
    • 63. Final67 Rectangles

      5:46
    • 64. Final68 Oval, Point

      2:34
    • 65. Final58 Todo List

      12:35
    • 66. Final59 Text Editor 1

      5:03
    • 67. Final60 Text Editor Functionality

      8:33
    • 68. Final61 Text Editor Functionality 2

      4:27
    • 69. Final69 Paint

      13:41
    • 70. Final70 Paint Fix

      0:42
11 students are watching this class

About This Class

Do you want to learn Python 3?

You have come to the right place, welcome to the Python 3 mastery course,

where you will learn how to create real-world python applications from scratch

Why should you learn python?

Python is one of the fastest growing programming languages on the planet.

Even compared to other popular languages. Python is way ahead.

It is also projected to be one of the most popular programming languages way into the future

It doesn't matter whether you want to focus on Web applications, Games, Machine learning or Data Science, Python is used everywhere.

Who is this course for?

  1. Beginners with no programming experience

  2. Programmers with experience in another programming languages

  3. Anyone who knows basic python but wants to learn more in depth

What you can find inside the course?

  • How to install Python 3

  • How to install Visual Studio Code

  • Variables

  • Operations with Variables

  • Casting

  • Code Branching (if, else if, else)

  • Python Data Structures (Lists, Tuples, Sets, Dictionaries)

  • Loops (for, while)

  • Break & continue statements

  • Work with files (create, open, write, append)

  • Exception Handling

  • Functions

  • Recursive Functions

  • How to debug applications

  • Modules and PIP

  • Object Oriented Programming

  • Inheritance

  • Protection

  • Iterators

  • Simple Algorithms (for improvement of problem solving skills)

  • TkInter GUI

  • Frames, Buttons, Entry, Grid, Menu, Canvas, Rectangles, Lines, Oval...

You will also create real-world graphical applications:

  • TODO list

  • text editor

  • graphical editor

We have over 80 high quality video lectures

combined with articles and quizzes.

So that you can test your python skills.

If you don't understand something or if you need help with something. You can always reach out to me. Mostly I respond within a Day.

At the end of this course, you will get a certificate of completion.

That you can put on your resume or on your linked in profile.

The course comes with amazing 30 day money back guarantee

So you can try the course, risk free.

So do you want to learn python?

Enroll today and I will see you in the course

My name is Luke, I am a programmer with over 5 years of experience.

I worked for companies like SAP and currently I am a instructor with over 70 000 students.

Transcripts

1. Introduction: welcome to buy three mastery. Course where you learn helps a great real world biting applications from scratch. So why should you learn? Python Python is one of the fastest growing programming languages on the planet. Even compare to other popular languages is way ahead. It is also predicted to be one of the most popular programming languages way into the future. It doesn't matter what you want to focus on that applications games machine Learning Our Data Science by Ethan is used everywhere. So who is this course for? This course is designed for beginners with no programming experience. It is also a good match for people with some experience in another programming language. But even if you already know basics of Python, you can learn by even more with this course. So what it confined inside, of course. Let's see. In the beginning we will and sell everything, and it's around it programs. Then you learn all the important concepts off programming like variables, conditions, functions and so much more. We also cover object oriented programming, improve your problem solving skills on simple algorithms, create graphical user interface with taking into, and finally we'll create some real world applications like Dex, editor or Simple, a graphical editor way have over 80 high quality video agents, combined rift articles and quizzes so that he can test your Fife instills. And if you don't understand something, or if you need help with something, you can always reach out. Mostly, I respond. Within a day at the end of the scores, you will get a certificate of completion that you can put on resume or on your late and profile the core skills with amazing 30 day money back guarantee so you can track course risk free. So do you want to learn python and roll today and else you're in the course? 2. Final01 - Install Python: Well, hello, gas. Send Well countered his lecture and this lecture. We will install the python on your device because in order to great Python program, you need to have python. So go to bath in that arc, or I will just put dealing in the resource and in here go to downloads and in here click on your platform. I'm on windows, so I would pick this windows. If you are on Mac, you obviously want to click on Mac. Okay. And as you can see, there are a lot of versions, right? You can download a lot of versions, but we will go with the newest one, which was released in 2018. So actually, here before bar Never mind in here. I will simply download the executed bill installer. So click on that. And this will download a file for you right now. You you have a choice. You can either install everything that includes the idol, the documentation, stuff like dad. Or you can customize the installation and you can basically pick. What do you want to install? Right. So that's up to you. Which one do you choose? But if you are a new users. I recommend going with the install now. Okay, so click on that. And as you can see, the python will start to in. So and I will see you on the other side. Alright, guys. Sent eventually, The python should be installed on your device. So cool. Now it says disabled path length limit. So you have something called Bath in your global variable environment and windows. You don't need to worry about it. Simply click on this one, and then it will ask you to kinda confirmed the change and you're click. Yes, and that's it. That's all you gotta do. All right. So yeah, Right now we can close the the Insult desert and yet 3. Final02 - Instal Visual Studio Code Extension: Okay, so I gather you're open d visual studio code. And right now we are going to install the extension so that we can debug and, like, do a for my ding off our code and stuff like that. Okay, so in here, go to this kind of I can. Okay. And as you can see, it's a extinctions and inside here, but dyp bay thin like this, and there should be a bison by Microsoft. OK, so simple. Click on this insult. You can either click in here and then click on install. And while we are installing in here, you can go through all the cool stuff that this extension does, right? So even there's even, like video examples. Right? So there's a suggestions, right? So as you type, it will automatically suggest you what you might want to use, right? It's also support debugging. I'm not sure ready, you know, right now what debugging is, but it's basically a when you run your program, you can step it out right so we can study program at some point when it's it's used when you have some buck in your coat. And that's why it's called debugging by the way. And but it's used when you have some buck in your coat and you want to figure out where is the problem right? Then you want to stop the application at some point right where deep problem occurs, and you want to figure out what have you done wrong? Okay, so we will get to it later on. And there's a lot of a lot of things in here, right? So you differently want to install? And once you install this, you need to reload it. So click on this reload button. And once you click on that button, it will basically take you to this page and you have the extension insult, right? When you have the disable and uninstall button, everything is fine. So yeah, that's pretty much it for this lecture. 4. Final03 - Hello World: Oh, guys, Welcome to this lecture and this lecture. We will create the first Feith and file. So let's get into it. Simply click on this new file in here and then type. Let's say hello dot Be Why? Okay, So, like this and this will basically create a new file. It's the same as, like, some text file or something like that, right? So nothing too interesting. Bad. What we will do is add some functionality, so we'll define a message, and a message will be equal to hello world, and we will bring to the message out. Okay, So on the next line, I was simply right in here, friend. And in your I'll pass the message. Okay. So as you can see the extension that we insult previously, Ganda tells me that I probably want to add the message variable that I defined in here. And it tells me that it is a string body. I don't worry too much about it. Okay. Once you're I d program, we would like to run D program. Right? So we like to execute a program, and in order to do that, we can simply click by right button on our mice in somewhere in here. And then so, like this run python file and terminal. So when you click on Dad, as you can see in here appears Hello, world. So that's basically the our message. Right? So what did we do? Well, we said, Okay, this message will be called hello world, and we want to bring the message. And when we refer to the message in here, it will basically take this stuff and put it in here. OK, so cool. That's pretty much it for this lecture. 5. Final04 Variables: okay? Gas and this electrical start talk about variables so worth as the variable Well, they're able is basically just a space and memory. Okay, so you probably know that computer have something called memory right. And you can store something in there. OK? And when you store something in there, you can refer to the place in memory. You can refer to it by the name, right, and you can choose the name. Okay. So, for example, this line what this lined us. But first of all, the message the MSG is the name off a variable. Okay. And we are basically storing this hello world somewhere in the computer memory. Okay, so I know this may take some time to understand. Computer takes care off the place where we want to store the hello world. OK, computer does everything for us, okay. And, well, basically, operating system, that's everything for us. Okay, But all we need to care about is how do we go the space and what are restoring in there. Okay, so another thing you may want to do is, for example, define a variable call the number you can have. How many off these you want. Okay. And in here, you can cite, for example, a 50. Okay, so that means I did find a number. It doesn't necessarily have to be in these quotes, OK, but yeah, you can define a number. Number is not within a quotes again to find a character which is like this sorry equals right. You always say variable equals something. OK? And in here we will type some character. Let's say a Okay, so So right now what we can do is, for example, bring two d number. So in here we bring the message. But we can also print the number so print and in here side number. And we can also bring d character so print and in here character. So cool thing is that when you define and store something in memory, you can refer to devalue that its start in memory while the name Okay, So you all you need to do is use the same name in here and in here. But what I will do is basically refer to this a that that lifts somewhere in memory and I will bess it into the spring function. And this function will somehow take care of the printing. And And when I run the application by right clicking and then right by thin file in terminal, As you can see, it's s Hello, world 50 and on a Okay, so hello, world is the message. Then it says the number, which is 50. And then it says the character which is a So another thing you can do is do this. I will change my mind. And I say that the number will be 20. So what happens now? Will this number be changed? Because right now I changed it to 20. Right? So what will be actually printed? And if you think that there will be 50 you are right. And if you think there will be 20 you are wrong. And what will be printed in here in here? Well, deeper into 20. Okay, so when I run this, you should see around Python file and terminal in here. That's this line, okay? And it's us 50. Dandy character is printed. Then we changed the value that a start and memory. Right? So we changed this 50 in memory and we set it to 20. Okay. And then we print it. We print. We still this This number is just like a reference. You can think of it as a arrow to somewhere in memory. So in here we take the reference to somewhere in memory. We point somewhere in memory and we say, Hey, I want 20 in here, okay? And then I print it. So that's about it for this lecture. I hope you understand everything. If you don't just ask me and I'll see you next time. 6. Final05 Starting Of Operations: Okay. So, indeed, previous lecture, we kind of defined some variables and stuff like that, but the variables are pretty much useless at this sporting, right? So we can do is set a space and memory to some value. Right, That's useless. So what we need is some sort off operations, right? We would like to do some stuff with the variables. So, for example, in here I will define a number two very about. And so I have the number variable and the number two variable. Okay. And I'll just get rid off all of these just to make it clear. And then what we can do. Well, we can define a new variable called number free, for example, and we can set it to the result off some operation. Okay, so for example, 10 plus 20 like this. But when we can also do it said it to a operation, and in the operation, we will take one variable as a para meter. Okay. So, for example, instead of the 20 we will use number two. Okay, so right now, what will be in the number free? Variable. Well, we have 10. Blast 20. So that's 30 right? okay. And what if I change this 10 to 50? Well, Judy number variable. Okay. Can I do that? Yes, I can. I can use how many variables I want in the statement. Okay, so in here, I will simply type number blessed number two. Okay, so right now there should be in the number four readers should be 70. Okay, So if I printed out, if I want to bring the number free, I simply type in here number free. And right now I will run the bison. And as you can see, it's a 70. So that's quite cool, right? We can now add, and in the water you can also do is, for example, will supply. Right? So if I run this, it should say 1000. Dad is right. And you can do like miners divided its Margallo and stuff like that so you can use all the cool operations that you learn in high school. Or maybe probably even earlier, right? Yeah, but never mind. So what? You can also do IHS do sound operations with a strings. So, for example, a string is just the sam sequence of characters, right? So basically, this one is a string. OK, so when each time you have these growths inside here we are referring to this as a string value. Okay, cool that. Yes. So let's define some string variable string var Let's go this one like this and let's set it to a okay and let's define another string gwar to for example. And let's say it too bbv all right? And what we can do with these Well, we can, for example, to find a string wherever free. And we can also at these up. Okay, So I'll just that string bar plus string. You are too. So what happens? Well, what will happen? What you want to add two strings? So for example, what will happen when you when I ask you to add hello and world together you will basically say hello world. Right? And the same thing will do computer So in here If I print the string wear to free Sorry, I will run it right. So run python file. And as you can see, it's us a BBB. Right? So it basically put those two strings together, right? And what it can also do is, for example, at another string so in here. You can add, for example, a no free dots that's up to you. You can use whatever you want, and when you run this, it should say a a free dots and then BBB because computer doesn't care pretty much whether he adds a variable or just a normal strength to computer. This this thing is basically the A a string. Okay, so he doesn't care. You can do all of these that a problem becomes when you want to add a number. So, for example, if they type in here, I will get rid of this South, and I will set it to number. So what happens when I want to add a string? Any number? So let's find out if I around the bison file. As you can see, there's a type error. Okay, so what the type error means? Well, usually when we're programming, you want to keep your code at least reasonably tidy. Okay? And somehow you probably don't want to like at a number to a string, OK, because it's it's like it doesn't make sense, right? It's like if I ask you to multiply, then by a what's the result of debt you don't know, right? And same is for computer. He don't know what a plus 15 means, right? It just doesn't make sense. So he basically telling as dad he's telling us, Hey, you have a type error on this line. And he also tells us the line where the error occurs, right? So string or free, equal string, war plus number. And he also says, can Onley conquered in eight strings, not in teacher to string. So number in the company's er is basically a in teacher a strength is this one. Okay, so he tells you basically the same stuff I already told you. So you cannot do that. Okay? And if you put multiply in here. Let's see what happens if I run this. It works. Why's that? Well, if you want to multiply a strength, it's going to make sense, right? So, for example, if I tell you, say hello five times Why do you say hello? Hello? Hello? Hello. Hello. And I think that was five times I'm not sure about Never mind. So you basically say hello five times and the same goes for computer. It kind of makes sense too. If you want to say a 50 times, it will basically add to the string bar variable a 50 times. Okay. So I can change this one to, for example, to so that you can actually see it. I don't want to calculate all the ace in here, but when I change it to two in here will be a because we're referring to this value, and then we are multiplying by two. So there's six ace in the result. Okay, in this variable, and we are then printing it. So yeah, I hope this makes sense and I'll see you next time. 7. Final06 Closer look at numbers: Okay, so let's take a look at numbers. So in Typhon, we have free types of numbers. 1st 1 is the in teacher. You probably know it, right? So number equals to some, indeed. Your valley, like five. Or it can be like that. This or it can be even minus right so we can have negative values. You can have positive values. That's cool. Bar. What do you get? Death is a decimal point in here. So you cannot have something like 5.0. That's too bad. Right? But while you actually can have it in here, OK, these number works. But when you add the decimal point in here, this number becomes becomes float. Okay, so you have a floating point number. That kind of makes sense, right? And you can also have a complex number. So what is complex number? Well, that's for further purposes. But if you know what complex number is, you can add the imaginary part by J. So, for example, plus five j Ok, so this is still a number. It's only a complex number, but don't worry about it. If you don't know so then what? He can also do ISS print D type. So, for example, well, not only bring detail, you can get to the type of variable by writing type and then inside parentheses. You right number. So what this one does? Well, we basically ask what type is the number? Variable. Computer says OK, Ok, OK, I get it. It's a float, and it is returned, right? It returns a float instead of this stuff, Okay? And then we print it. So if I run this program, it should say, Yeah, class through load. So why's why's there declasse junk? Worry about it right now. Okay, just the important thing is that this a float. And when I remove this stuff and say only five and run this, it should say end. Okay. And if I add, like to j, it should say complex. So if I run this, it's a scam plex. Okay, so that's how you can figure out a type of a variable. And nothing I may want to show you is, for example, that you can at the variable. So, for example, if I dive in here number and then number two and that will be just a floating point number if I add in here number free and said it to the number two times number. What will be the type of number free? So, yeah, let's let me change this one so that it is more interesting. What will be the type of number free? So we have two times to that five. So that's a five right that you think that this might be a in teacher, right? God, it's not. It's a float. So if I run this, you will believe me. So in here I will just I number free. So we are asking 40 type of number free. And, as you can see it says Float, Why is that? Well, even though the number is five, the number is 5.0 because the computer knows that he's taking a float and he's taking a in teacher. And what is more precise, right float is more precise because it have the thing. That's, um, a point, right? So what will be the result? Well, we would like the result to be the most precise number, right? So it will also have the decimal point. I hope that makes sense, right? So if I bring this, it should say 5.0. Okay, So if I run this it says 5.0 Not only five, but 5.0 Even Dodi number behind the decimal point is nothing the computer still like Like add the precision. Okay, cool. So does very much it for this lecture. If you have any questions, feel free to ask in Elsie next time. 8. Final07 Casting(Changing data type): All right, let's take a look at casting. So let me show you an example. You have a number, and it is a string that have five. OK, so then he would like to add to it A Let's say another number. So number two and that will be a sen. Okay, so that's basically a a string rights of string variable like this. So, as you know, from previous lecture, if you do like string where plus number two, we will get a error. Right, Because we cannot add these suit right because of the type. But what we can do is change the time. So for example, in here I want to type number free, and I would like to do the string war plus the number two. So number two like this, and but this will be the era, right? So if I want t, I need to change the type off the string variable so that we can do the plus operation. And in order to do that, I can do it simply by writing end as a teacher. And then I put into the parentheses, the name of the variable that I would like to convert into a strength. Okay? I hope to make sense. So if I now brained d number free, let's see what the result will be. So it's 15. Why is that? Well, we have five in here, right? You are a human. You know that this is a five, right? But computer is not sure. So then when we say, Hey, I would like to turn this string and say in teacher, would you do that? Computer says Sure. Hey, looks at this string and finds out that there are only a numbers right? And there's only one number. So that's cool. And he converts it into a strength. Right? Because he's smart enough to figure out that five is a five right and s Oh, sorry. He converts it into a in teacher, right? So then we have a integer five and integer 10 and there's nothing holding us back, right. We can simply do 10 plus five and there will be 15 and dead will be stored in the number of free variable. Okay, So computer even can deal with a multiple, like multiple digit numbers. Right? So if I if I put in there 500 it says 510. Right? So he figures out. Okay, this whole stuff is basically a number, right? But if I, for example, put in here G, let's see what happens. We get a error, right? Why is that? Well, we are trying to say that this is a teacher, but it's just a G. How would you turn g into a number, right? It makes sense. So make sure to type in here a some number. And yet so another thing you can do is turn it into a float, right? So with a that some of point. So, for example, let's put in here like 1.55 whatever and run this program. And as you can see, it's a $11.55 so it can turn it into a string. Right? So it gets sorry. It can turn it into a float. Okay. And another thing you can do is basically turned the number into a string. So do basically the exact opposite. So in here we will have flag g, and then the number two is number and in here will be string variable to Okay. So what we would like to do ISS at two. D, g 10 so that we have G 10 as a result. Okay, but if we have it this way, it wouldn't work. Right? So if I Sorry if I run this, we get a error, right? We cannot add string that we Sorry, we cannot at in teacher into a strength right and then make sense. So we would like to convert the number into a string, and we will do it exactly the same way. Only the sign we dive in here string. So if I run this, it says g 10. And why is it working? Well, sing cases before the computer basically takes a look at this number two and says, Okay, this is just a number, so I will turn it into a string. So we basically adds these these growths, right? And then it returns it in here. So we have a 10 and G and we will put it together, and it stays G 10. Okay, I know this doesn't make sense. Like this is just for teaching purposes, okay? And nothing you may want to ask is what happens if I want to change to a string a string All right, so let's say I somehow missed Stop and I would like to change a string value into a string . Well, Computer says, OK, you would like to change a string into a string, but it is already a string, so I will. I won't do anything right. And, yeah, it's going to make sense, right? So that's pretty much it for this lecture. And if you have any questions, feel free to ask, and I'll see you next time. 9. Final08 Strings: Okay, so let's take a closer look at strings. So what is strength? Well, this is a string. OK, bod this. It's also a string. So you can either use the devil quotes or single quotes. And yet these both think are the same, right? So they are equal. Okay. And what you can do with strings Well, there's a lot that you can do. So for example, I will define a string variable, and I will call, I will set it to hell. Oh, Okay. So some space and memory hello as a value cool. So let's say that I would like to bring the first character that is Indy String. I can do that because the computer represents string as a array off characters. So basically, even though this is still in memory, it splits it into single characters. And they are next to each other in Indy memory. Okay, so I can ask for any character that isn't the memory Cool, right? So if I want sprained, for example, the first character, I can do it simply by writing string war that will bring the whole string OK, bar What I can also do is ask for a specific character. Okay, so, for example, character at index zero. So if I run this, it should bring age and a dust. Okay, So why's that? Well, first of all, we are indexing from zero bad. And so this the h, this character at index zero, this one is on index one. And so on. So on. So we are basically accessing the string, but only the small part. Only one character firmly string. Okay. And we can ask for any character. So if I ask for the next one now, it will print E right. As you can see their c e. And they can do it with, like right there. 01234 Okay, so the last last should be on index for, so that should be Oh, okay. There it is bad. What happens if I go to five? Right? Five. It's somewhere. That is not It's behind a string. Right? It's more that I can ask for. So if I run this, I get a error. So this process strength index out off rage. So what that means? Well, I basically reached too far, and I am trying to grab something that is not in the variable. Okay, about if I add some character in here, it would work and it will bring h And another thing you can do spring to a character's off some part. Okay, So for example, I want to brained from position one two, Position five. OK, so when I run this, you will see the result. Okay, so I am grabbing on Lee a sub string off this whole variable. Okay, so I am basically taking Oh, I'm leaving out d character at index zero and I am taking the character on index 1234 Right . The five is not included. That's why this h is not in here. Okay? So you can do like, all kinds of stuff with this, you can even trim it more, right? You ride Right now, the O is not included. Also, you can start a different physician. So, for example, from two right, that's up to you. And that's quite good. That's quite useful to write. You can simply just pick a subpart off string and it's very easy to do so OK, so another thing that you may want to do is figure out a length off a string. So how do you do that? Well, remember, as we do, the dive definition and stuff like that simply type in here. Land is a length. And then we Basson there, the string variable like this. So this will print how long the strength s. So if I run this, it should say six, right? 123456 Go. Right. So we can we start indexing from zero? So the last character that we can index its own index five. OK, that makes sense. I hope it us and nothing you can, For example, do it is get rid off white spaces before and somewhere at the end of your string. Okay. And how do you do that? Well, simply, I've been here String guar then dot OK, so dot that's important. And then you can simply type strip and once again parentheses. Bad day will be empty. Okay, So if I run this right now, it brings the same string. Right? This is the same string. The content is the same, right? And the spaces in between the characters in between the soda words are there, right? But the spaces in front and at the end are deleted. Okay, so that's quite cool. If I printed without this, you should be able to see the difference, right? There's a spaces in front and behind. You can see the spaces behind. But trust me, they are there. And yes. So that's one thing that you can do. Okay, Another thing that he can do is simply turned a string into a upper case or a lower case. Okay, so for example, in here I will type shut out. And I wanted to seem like I'm screaming right? Right now, it doesn't seem like I'm screaming. If I bring this it just say, shut up and it's just boring. But if I kept allies it, it would look much better, right? So if I at a dart into the string gwar dot and then kept allies and then Bren theses, I will simply run it. And as you can see, the first number, it's kept allies right there is. So that's gonna cool, right? And another thing you can do is make it even a brutal gaps lock. Right. So do a upper as a upper case right on. And when I run this, it's like shouting at me. Shut up! Right? So, yeah, it's too bad. But anyway, right, you can do this stuff. You can turn it into a upper case, and you can do the same thing with a lower case. So, for example, if I do a shut up like this, right, I concern it into a lower case by tapping lower, right? That should make sense. Kind of right. That's a good name for a lower case method. So that basically takes the value of the string and turn only characters into a lower case . So shadow and there you can also do a stuff like replaced some character with another one. So, for example, in here I will do sh s h s h s h. And then let's say that I want to replace the whole thing about the suggestions of the extension that we installed is that it tells you okay, you want to replace right? I know that method and it tells you in here you type the old character Denny attacked in here, the new character and Dan, you type in dirty count, but the count doesn't necessarily have to be there. OK, so for example, if I want to replace the age with a A, I can do that. So if I run this, it says a S a s a instead of s HSH, right? So it basically takes all the ages from this string and converts it into a right, and then it brings it to you, and you can also assign it to a another variable and then bring the variable. So if this doesn't make sense, maybe try it like this. So string there, too, will be equal to this one. Okay. And then we'll brandy string bar to okay. Didn't might give you a little bit off sense, right? The result is still the same. Okay. And another thing that he can do is split these strings so that you have a difference brings. Okay, So if I, for example, with a space inside here and I would like to split it, Okay, I would like to start at a bar. I can do that. So, in here, I will, like, right a split. Okay. And I would like to split it when there's a space. Okay, so each time the space occurs, So that means in here and in here. I would like to break it down. Okay, so in these string war two, we will have a array of a sup of a strength. So if I run this, you should be able to see it. Okay, as you can see, So basically, the square brackets stands for array. Okay, That's a data structure, basically the same as the string. Right. But inside, you're a We have something called elements, okay? And the this one is a string. This one is also a string, and this one is also a stirring. Okay, so, yeah, this don't worry too much about if you don't understand the rate concept. We will get to it later on in this course. Okay, so, yeah, that's pretty much it for his lecture. If you have any questions, feel free to ask And Alison next time 10. Final09 Getting the User Input: Well, hello, gas. And welcome to this lecture. In this lecture, I will show you how you can take input from a user, so that will be quite cool. So let's get into it. First of all, let me define a message. Variable, Right like this. And let's say it should say something like, Let's say your name. Okay, So that's just the thing that we do. We ask for a name of the user. Okay, then we would like to bring the message so the user can see it. So bring message so far you over and know everything, right? No need to explain. So right now, we would like to get the name of the user. Right? So we would like to use her to decide the name on his keyboard, and we would like to work with that. We would like to store it as a variable. Okay, so how do we do that? Well, and here recent, let's add the name of the variable. So user name, for example, like this, and then we'll assign it J vary off what to use the road. And once again, computer does all of the heavy lifting for us. All we need to do is simply type in here inputs. Sorry. Input like this, and it will basically as the user to enter something. Okay. And then it will take these something, use a road and set it to as a value off this user name variable. And then what we can do is, for example, brained a string that says hello. And then we will add the user name user name. Okay, so it's just it's a simple application. So if I run this, it starts and it says your name, and then it waits for me to input something. So I will simple type my name Luke, and then hit Enter. And this will basically a fire d input and put deal Yuk as a value off this user name. Okay. And then we can print. Hello, Luke. Okay, so that's quite cool, right? You can make a simple applications. Why are this so? Yeah, And another thing that you may want to find out is that I can ask for a type off the user name so that you can see with what type it is. Okay, So if I run this yeah, I will just start, Luke out story. I need to click inside here. Okay. And in here type Luke. And yet it burns l a look same as before, but it also tells me that it is a string. OK, so now you may wonder what happens if I type in the year Something like to write to is not a valid name. So what happens? Well, it's not a number. It's a string. Okay. So even though I typed to the user, input is always a string. OK, so even though you think that this is a number, it still works, right? You can at a string and string and as you can see, it is off glass string. OK, so the type of the user name is string even though it is too. So, yeah, that's very much afford his lecture. If you have any questions, feel free to ask him out soon. Next time 11. Final10 - First Application!: All right. So let's get to the fund bar. We will. Great. Our first kind of useful application, and it will be a calculator. So what? To get into it. First of all, what calculated us? Well, we will not create 80 conventional calculator with buttons and stuff. Well, basically, ask user for two numbers, and then we will do Oh, the blast Divide times operations for the user, and we will bring it out on a screen. OK, so let's do that. First of all, we would like to bring to the user. So print, and then we would like to bring something like enter first number. Okay. And then we would like to take the input. So first number. So we will create a variable. And in there we will store whatever use a road, okay? And then we will ask for a second number, so I'll just copy, Pasted to say sometimes. So enter second number. And in here I will also change the name of the variable to second and cool. So we have t two numbers that use a road right now. What we want to do is do all kinds of operations and then bring it out. Okay, So can we do this brain and then first number last second number. What does work? Well, you may want to pass a video and think about it, but I can tell you right now it will not. Because if I add, for example to Oh, sorry, I need to click in here. If I add two and five, it should be seven. Right? But it's 25. Why is that? Well, these two are strings, right? So we are We are not working with in teachers. We are working with strengths, so we can't simply do this. So what we can do? Well, we can change it to a in teacher. So we basically take what do you use the road? Change it to in teacher, and then set it as a value to the first number. And we can do the same inside here. And you can even change it to float. That's up to you, right? I will just do it within teachers. And then when I run this, it's should work. So if I type in here too, and five, it's a seven. So we get a calculator. Very, very basic calculator that yet we get one. So what we want to do? Well, we would like to bring all the operations right. So blasts times divide and minus right. So times divide miners, we can even do module. Oh, right. Okay. More djalo. That's up here. And we can Right now we have a working calculator. If I run this and type in here, for example, Sen and five area have the results, right? It says Sorry. I will make it a bit bigger. Five. So it's a 15. 52.5 and five and zero, which is direct, Right? But I would like to do is going to make sure that what I'm right now, as I'm looking at these numbers, I'm not sure what is. What's the expression right? That the results into it. So I would like to bring for example, 10 plus five equals 15. Okay, So in order to do that, I will simply turned into a string. The first number. Then I will add the bus sign. OK, so like this and I'll put a space in there. Then I will put into a string the second number, second number. Okay, then I will add the equal sign to it, and then I will finally put into a string the well, I will once again conquered in eight. It and I will put into a string the results off this operation. Okay, so I need to also close this one up and cool. So if I run this right now, it says inter for his number five second will be, for example, eight. And as you can look at this first line, it says five plus eight equals 13. Okay, so if if there would not be type conversion, this wouldn't work, because we will try to add a number and a string. Right. So we need to convert the numbers into a string, and yeah, and then we simply contaminated with a characters with a strings. Okay. So as your challenge, you need to change all of these so that in here, it says, like, first number dimes. Second number is equal to U. S. So it looks basically the same as in here. Okay, so, yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask And Alison next time 12. Final11 - Advanced Operators: Alright guys. So in this lecture, let's take a look at some more advanced operators. So let's get into it. First of all, I will define a number and let's say it, it will be a 10. And then I will define a number two and I will put it as a result. For example exponential. Okay, So for example Zan sooty exponent off to Okay, So if I then bring the number two Okay, you should be able to see it. You should be able to see quite big number. If I run this, it's 100 right? Because 10 to the power of to is 100. And if I run this again, it will be 1000. Right? And so on. So on, Right? 10,000. So yeah, that's the exponential in. Okay, then what he can do is do a floor division. So what? That means. Well, basically, the result after dis operation will get rounded. Okay, So if I run this as you can see, it's us to Why is that? Well, then divided by four is to doubt five. Right, But since we are doing the floor division, we are getting great off everything that is behind the X behind the decimal point. Right. So we have only two. Okay, cool. So another thing that we can do is do a something like plus equal. Okay, So for example, right now we set number 2 to 2. Okay? And then we can do something like this. So number two plus equal one. So what this will do? Well, it will just add this one to devalue that it's currently stored and number two, and that it will store it as a result off in number two. So if I run this, it's us free. Okay? Because number two is now free. We took d to that was in the number two very ever before, and we add to it one and store it as a new value to the number two variable. So basically, this line is the same as typing number two equals number two. Last one. So, yeah, that's another cool thing that you can do. You can refer to a variable in the expression and then assigned the result off the expression as a value to the same variable. Okay, this this is find this will work. OK, so if I come in this line out or if I just delete it, Okay. You should see that. The result The number two is still free. So if I run this, it says free. Okay, so these two lines are the same. Okay, Cool. And right now, I touched on another thing that I wouldn't want to mention, and that is Commons. So in programming, you want to write comments, because when he writes, um, complex application, you need to type something to a line to know when when you are looking at the gold. Like one month later, you should know what this line does. Okay, So when you want to type, come in. You can say this line ads wanna right and stuff like that. And what this means. Well, the computer want vary eight this thing as a expression, right, He will just reach this hashtag, and then he will say, Okay, what's behind is just for the user, not for me. So I will not take a look at what it says. Okay, so yeah, cool. Another thing that he can do is instead of display sequel, we can do time sequel minus equal. You can use all of the operations that you know. Okay, so, yeah, For example, if I do times equal one, this should just say free. And if I come and this line out, it will say to okay, because two times one is two. Okay? And if I change it to it will say for okay, Cool. And yeah. So that's one part of the advanced operation that he can use. If you have any questions, feel free to ask End Alice, You next time. 13. Final12 - Logical Operators: All right. So the comparison operator are used to compare to baddies. Okay, So for example, in here I will type number, and I'll set it to 10. And in here I will write number two, and I will set it to 20. And if I want to bring out whether well for yeah, I will print it out. So let's bring some very ever called result. And in here we will define the very book result, and this one will be equal to, for example, something like number. It's equal to number two. Okay, So if we want to find out whether two numbers are equal well, whether two variables are equal, we right to equal signs because the one equal sign is the assignment operation. Right? So we need to type in here to seek aside, And when I run this, it says false. So why is it? Well, 10 is not equal to 20 right? So that's why this once is false. And then if I type in here, for example, not equal to 20 which means this exclamation mark equal side OK, so this one means not equal. So if 10 is not equal to 20 we will have a true And this should say true, if I run this, it's as true. Okay? And if I, for example, changed this 1 to 20 they are equal now, right? So 20 is not equal to 20 is nonsense, right? There are the same. So if I run this, it should say falls. Yeah, and it does. Okay, So another kill thing that he can do is, for example, ask whether a number iss smaller or equal to something. Right? So all the operations did you know from middle school. So if you type in here, this one, it says number is smaller or equal to number two. So if I run this, it's is true because they are equal, right? And if I, for example, change it to 19 it says false, right? Because sorry. It says false because yeah, 19 is smaller than 20 right? So yeah, but if I change it to this one and says number is greater, Dan number two, it should work. So if I rend us, it's as true. Right? So these are all the logical operations, Dad, You may want to use okay sometimes. And they are heavily used in condition and we will get to it later on. Okay, so right now, all you need to remember is that all of these operations are returning a value that is either false or true. Okay? And yeah, that's about it. So you can compare to values using to ICO signs again. Comparative Using not equal. So a explanation mark and equal sign. OK, And then you can use all the arithmetic gonna operation right. Greater than smaller than stuff like that. And another thing that we have is a logical operation. So what is a logical operation? Well, a logical operators are used to combine conditional statements. So, for example, this thing is a conditional statement, okay? And we can combine them together. So if I, for example, put a parentheses inside here and then type in your end and another conditional statement, I can do that. So, for example, in here I will type number is equal to number two. Right. So this one will be obviously false. Why's that? Well, I am asking the end. Basically, the this This is a logical operation. If at least one of the expression is false, the result is false. But if all of the expressions are true, the result is true. Okay, So in order for the result to be equal to true, we need to have all of these expression equal to true. Okay, I hope that makes sense. So if I run this, it says false. Why's that? Well, number is not equal to number two, right? So this one is false. And even though this one is true because number is greater than number two, it's still the final result. Judy and operation is false. Okay? And right now I can also use the or operation. So what the our operation does well. The result is true if at least one off the expressions is true. Okay, So it is true if at least one off the expression is true. So this one is true. So even though this one is false, the result is true. So if I run this, it's is true Cool, right? And yes. So if I, for example, changed this to the opposite So if I say number is smaller than number two, which is false, and then do our operation and then another falls, the result will be force. So if I run this? It is false. Okay, because there's none off the expression that will result into true. Okay. And a nun thing that he can do is the negation. So what negation does? Well, it basically flips the value. So if you have a false, it will flip it into a true And if you have a true it will flip it into a false right. So how do you do that? Well, simply type in here Not so you can also read this stuff, right? So if you if you read it from left to right, it says the number is not smaller than the number two and the number is not smaller. Dandy number two. That's true, right? So if I run this, it's Astrue even companies or knows that so, yeah, the these logical operations are kinda maybe a bit more advanced. So don't worry. If you don't understand everything now we will get to it even later in this course 14. Final13 If statement: All right, so let's talk about conditions. Conditions are a great too, and you will definitely use it in your applications. So it's important to know how day works. So first of all, we get there, d if condition and what that allows us to do Well, it allows us to control which which part of code will be executed. All right, so I'm quite sure that this doesn't make sense right now, But think of it this way. If you tell somebody if something is happening, then do something, OK? That's usually where you tell something to people, OK? And you tell the same thing to computer. So if some condition is true, do Sam coat. Okay, so let's let's try it out. So if you want to define a if condition simply type in here, if then you type the condition. So if, for example, bigger number is greater than the smaller number Oh, sorry. Smaller number like this I can type and then do something. And the dent Pardew defined by column and then you on the next line under you write what you want to happen. Okay, So for example, you can print something on the screen like bigger number is bigger. Who would have guessed that? Right. So yeah. So what did us? Well, computer evaluates this thing as a Z. Just normal comment. He goes and checks out. All right. There's if so, I need to check whether Diskant Ishan is true. And it's then greater than minus five. Well, yes, it iss, right. So Dendy computer looks at the lines that are in here and executes them. OK, but if this condition is false, this line will not be executed. So let me also put something at the end of the program. So, for example, I will print in here the program ends so that you are sure that the programme ended. Okay, and let me run this thing. So as you can see there, assess bigger number is bigger and then program ends. Okay, so basically, it happens. As I said, right, this condition were true. So this line were executed, all right. And if I, for example, change this to say bigger number is smaller than the smaller number, which is a complete nonsense, right? Ah, this line will not be executed and we'll see only the program aunt's. Okay, so If I run this, we should be. Yeah. We see only the program ends, right? This line is not in here. Okay, go. So this is basically how the if condition works, you can put in here multiple statements. So for example brand I know. I don't know, right. You can do whatever you own right against assign a value to this right. And this one will be changed, right? And then I will run it. And as you can see, they are I don't know, bigger number is bigger and then deeper. Ram aunt's Okay, so yeah. And how do you define which line will be executed if the condition is true? So as you can see, these two lines are executed. If the condition is true and this line is executed no, no matter what right if the condition is false We still saw the program ants. So from dad, you met figure out dead. This step is extremely important. This stab defines which line we want to execute if something is true. Okay, so these steps are extremely important When you want to nd if condition you simply start typing from the beginning of the line. Okay? so the space matters and yeah. So what happens if I, for example, forget about us, and I put this sprint in here? Let's see if I run this. As you can see, there's a error right now. The computer go study if condition and there is something that is true. And he says, like, All right. All right. I want to execute some code and there isn't any. Okay, so So we get an error. Okay? I hope that makes sense. And what happens if I put the condition to be false? Right. So if I say bigger number is smaller than the smaller number, which is nonsense, this is false, right? So this condition is not met. So will it matter to computer if I run this program? As you can see, it doesn't matter. Even if the condition is false, we still need to have some statements in here. So so that the computer knows right that there's some cold he can execute if the condition is true. All right. So yeah, that's very much it. That's how you can define a condition. You can have multiple off them, right? So we can define another if condition in here and say, for example, on no bigger number is equal to the smaller number. Right then right? Going and in here some stuff. So you can even, like, assigned a value to the bigger number. For example, you can do whatever you want in here, OK? And yeah, that's pretty much it for this video. If you have any questions, feel free to ask End al soon exam. 15. Final14 Else If Statement: All right. So in this lecture, we will take you. Look at the else if condition. So what is the else if condition Well, let me write an example. And then let me talk you for it. Okay, so we writes him to l. F like this. So not the entire else. If, but only LF all right. And then we write some other conditions. So, for example, bigger number and is greater than smaller number. All right. And that color. And then we can, for example, bring something, right. So maybe this line, I will just take it from here and based it inside here. All right, So what that means? Well, the else if must be directly under a if branch. All right, so when one ends on the line under, we need to have else if, Well, we don't necessarily have to have it in there. Right? But if I, for example, type else if somewhere else So for example, in here, we would get an error. Right? So if I run this, we get an error dead, the else if it's invalid, right? Because we need to have the else branch directly under the if and this should make sense because right now I'm about to explain what the else it does and the else of basically takes a look at the condition. Only if all the if branches above were not met. Okay, so if this is false, right? So if this condition is false, this goat will not be executed and the computer goes and checks this else if and he says All right, so this condition above was not mad. So I will check this one and see if I get lucky. Right? So he checks this condition and see that this one is true. So that's cool, right? And he can execute this code. Okay, So this else if branch is executed only if the if branch above Waas not met. OK, this is important. So if I run this right now, you should be able to see the bigger number is bigger. All right. And why is that? Well, this condition is nonsense, right? This is false. So this line is not executed. Then the computer goes to the else if branch and see that this line this condition is true . So he executes this line. All right? And what happens if I, for example, changed his condition so that it is true What happens? Well, the companies are ghosts in the it branch and see that this one is true. So he says, Okay, cool executes this code, right? Same as before. But then he goes out and kind of skips this else if Branch Okay, so all the code that was inside the else of branch, he won't even a very A D condition, right? So he says, All right, I already get one condition. That is true. And that's enough for me. And he goes directly on the line. Eight in here. Okay. So yeah. So let me, for example, Rungis killed. As you can see, there should be printed, I don't know. And then the program and right? So, yeah, yeah, it's exactly as I said, right? And it doesn't matter whether the condition is true, even though this one is the same condition. So it is also true the computer doesn't evaluate this thing. Okay, so yeah, and another thing that you can do is for example, I will say this condition is false. And then I will say this condition is also false because bigger number. It's not smaller than small number. So what happens now? Well, the computer simply goes into the If and says All right, this is false. That suit that And he says, But there is the else of brands so cool. And then he goes inside this condition and figure out that this is also false. So, yeah, he doesn't execute even this coat. And then he goes directly under. OK, So as you can see, none of this prince happens, right? We only see the program ants inside here. So yet what you can also do is the find multiple else if branches. So, for example, else if and as I said before the else, if must be directly under the condition or directly under another else if condition. All right. So in here I can, for example, say bigger number is greater than smaller number, and then I can bring I know something that isn't in here. So this this is happening all right? And if I run this program, the this is happening should be printed as you can see it ISS because why so computer go suit is if it's false. So he skips this Go students else if it is also false. So he skips it and go studious else. If right. So the last else if. And he figures out that this one is true, right? This is true. So he burns this and he's on. Right? So this is basically the else of branch, right? I only want to make sure that you understand that if I put something in here, we get an error. So, for example, if I said the small in number to 10 in here, right, As you can see, it is not part of the else branch because there is no space in front of it. Right? So if I run this code, as you can see, we get the error because the bigger number right? Because this line, basically the line nine is not directly under another else average. Okay, right. It has to be directly under. All right. So, yeah, that's pretty much it four days to do. If you have any questions, feel free to ask. And I'll see you next San 16. Final15 Else statement: All right. So let's talk about the else branch. What is the Elbridge? Well, else branch is basically something that we can use to define something that will happen if none of the conditions above was math. Okay, So if I, for example, type in here else and then I write only the come All right? And then in here, I burned, like, for example, e no else branch well or just else. And yes, So this will be printed, or this code inside the else branch will be executed on Lee if all of the conditions above were not met. Okay, I hope that makes sense. So, for example, if I type in here Ah, not a nonsense like this one, right? This condition will not be met. This one also will not be met. And this one also right? So as you can see, we see this. L sprinted. Okay, so, yeah, As I said before, this couldn't compete to go study. If figures out this is false, okay? He's sad. Bad, right? He cannot execute this line. So he goes to this else if and tries and still fall. So he also cannot execute this line and goes to his last else if and he really hopes this will be true, that it is not so. He cannot execute this line that thankfully we have the else branch. And inside here we have the Brent else. So computer finally finding code he can execute. All right. I hope to make sense, right. So the else if Els branch needs to be placed as a last statement in the if statement. Right? So if you have all of these statements above, the else must be the last. Because we are defining something that is happening when none of the conditions were not met. So it kind of doesn't make sense to put some other else. If in here. Right, so, like this, right? The that shouldn't make sense. Sorry. Like this. And yes. So just so you can see, I will just put it in there. And as you can see, we will get a error. So if I run this program, it should say error. Yeah, else. If right, it's not placed directly under else if or if All right, so we get an error. All right. So the else must be directly under else if or if and it must be the last condition. All right. So, for example, you don't necessarily have to have the else if in there. So if I go and write, for example, if a bigger number is smaller or equal to smaller number All right, we can, for example, bring something. All right, So something and yeah, I accidentally click on caps. Look about, never mind. And in here we defined the else bridge. All right, so this this works, we can define a else bridge when we only have a if a both. All right, so in here real brings something like else too else to all right. And if I run this program, you should be able to see else to Yeah, you do. Because the else to iss this this branch, right? This condition above was not met. So this will not be printed and then compete ago. Studious else branch and he finally bring something. All right. I hope this makes sense. The else condition is, in my opinion, the easiest wants to understand, right? Basically, if all of the conditions above were not met, the else condition will be executed, and yeah, it must be exactly at the end, off every if statement, right? So, yeah, you can have if statement without the else condition. Don't get me wrong, Right? This this is still well, it all right? This still works, all right, But the else statement. If there is a l statement, it must be placed directly at the end. All right? And that's pretty much it for this video. If you have any questions, feel free to ask, and I'll see you next time. 17. Final16 Practice: All right. So let's create a functioning application that will test whether the number that use road is a positive negative or a zero. All right, so let's do that. So simply in here we will bring something like, bring something, like I know inter number like this. Then we'll ask 40 number. Why are the input right? You should know that. So in here I will define a new variable, cold number, and I will simply get the input from the user. All right, so right now, we also need to change the data type of the input that the user out because this is a string, right? So we will change it to a integer like this. And then we have a real number in this number of Arab. So what do we want to do? Well, first of all, we would like to check whether the number is smaller than zero. Right? If it is slowing down zero, we would like to bring that the number is negative. Right? So let's do that simply in here type if and then number is smaller than zero. And we would like to den Brende the number IHS negative. All right. And then what we want to do. Well, in other case, if the number is equal to zero, we would like to bring the number is zero. Right. So there are a couple of ways we can do that. We can either to find another if condition, All right, that we can also do a else, if right. So since we are checking for the same number, I would probably use the else if but every go with if there is nothing wrong with that. All right, But I'll use the else of branch. And in here I will check whether the number is equal to zero. And if there s arrow, simply print number zero right, because it is zero. All right. And the last case is that the number is greater than zero. All right, But is there any other case if we go to this point right? We know that the number is not smaller than zero. Because if it was smaller than zero, we would break out right. And we also know that the number is not zero. Because if it were zero, this condition would be met. We would bring number zero and then we would break out. All right. So what we can do is defined the else branch, right? So else. And then we can print Number is positive, right? Like this. Right? So So let me go for it once. Once again, this else branch is basically the same as typing else. If number is greater than zero. Right? So this is the same thing. Why is dead? Well, we have free cases that can happen, right? The number is either negative, right? The number is either positive or the number is equal to zero. All right. And if you remember correctly, howdy else. And if else and all the conditions work, it works that we first of all, check for condition. If it is true, we do the code and then break out. All right, so the other conditions are not met. All right. And then if the else F condition is also through, we check 40 condition, right? If it is true, we bring this line and then once again break out and continue with the lines directly under all right and right. And if all the conditions above we're not mad, we go to the else branch. All right. So this thing is basically same in this case, it is basically Samos typing in here. Only the else, right? So if I run this program, it asked me to enter a number. I will enter, for example, a 50. And it's as number is positive. Why is that? Well, number is not smaller than zero. Number is not equal to zero. And we go to this else branch. All right, So if I, for example, around this again and put in here zero Oh, sorry. Put in here. Zero, we get number zero. Right? So this is working. Why is that? Well, we check this condition. It is false. So we are not printing this line. Then we check this condition. It is true. So we bring this line and we skid the else bridge. All right. I hope to make sense. And if I run this program once again and I've been here something like minus 50. Oh, my God. You have to click in here and I minus 50 we get the number is negative. Why is that? Well, number minus 50 is smaller than zero. Right? So we print this line and then we skip this whole killed. OK, so that's one program that you can use for some reason. If you are not sure whether number is positive or negative, but it doesn't matter, it's mostly 40 teaching purposes, right? So, yeah, if you have any questions, feel free to ask, and I'll see you next time. 18. Final17 Lists: All right, So what ISS less well, list is just a special variable in there. You can store multiple values, all right, so it can keep, like, multiple values. It's You can think of it as a variable in which you have a series of variable and each of the variable inside. It's called Element. All right, so let me just find one this for you. And also, I refer to list as a race and yeah, because in by thing, you don't necessarily have a race. But in other programming languages, the list is basically equal to array. All right, so the array and list are almost the same. All right? If you ever wrote a program in in any out of programming language such a c or C plus plus, you probably know erase. All right, But anyway, let me get to it. So, for example, if I defined a list variable and I can set it to some value and each time we are defining list, we use square brackets and inside rewrite the values. So, for example, like apple, I know Google, whatever I know stuff, whatever. And then you can bring to the list for example. So if I dive in here brained and list bar like this and around this program, it should be able to see the list, as you can see, Darius. And yes, So you can also change the value, right? So we can access each element in D list and how you do. How do you do that? Well, for example, in here I will to find a new, very ever called element like this. And I will set it to list variable on index zero. All right. And then I will print only the element, and let's see which one it will be. So if I run this, it's a Snapple. Why is that? Well, we have these same indexes as with strengths. So if you remember correctly, this one is on in the zero. All right. This one is on index one, and this one is on index to all right. And if we try to excess something on index free, we get a error. So if you try to run this, we get an error. So if I run this as you can see, the index is out of range, right? Why is that? Well, there is no guarantee Ford element. Right? So, yeah, another thing that you can do is, for example, change a value. All right, So if I, for example, will ask 42nd element, right? So this thing maybe a weird from the beginning that you ask 42nd element wire one right, that that might be a weird for some people that trust me, you will get used to it. And you can, for example, changed the valley. So I want to change value off the second element. OK, so for example, like this, and I would like to change it to, let's say, Microsoft like this. And so what happens? Well, I changed the Google to Microsoft, and then I store it into this element variable, and then I print it. So if I run this code, as you can see, there is Microsoft. All right, so that's basically what you can do with list. There are a much more stuff that you can do with less. This is just like a beginning, right? So you can think of it as a list off individual variables. Right? So each of the elements right are basically a variable that you can access via the index. And yeah, and you can change the value. You can store the value. You can do stuff with Dad, right? It's up to you. And yes. So that's pretty much it for this lecture. If you have any questions, feel free to ask and I will see you next time. 19. Final18 Tuples: All right. So what is a topper? Weld separate is basically the same thing as list Onley in topple. You cannot change the elements. Right. So you cannot change the value of elements. So let me show you, for example, in here, I will create a Sorry. It's up a variable. And I would define it like this. Right. So you use parentheses and inside you ready elements. So, for example, at both and Guga and then stuff. All right. Like this. Right? So we created a new temple. Then what we can do is, for example, said the try to set the value on Index one so same thing as before. Right? And we can change it to, for example, d dd whatever. And then we can bring some element on index one. All right, so, print, it's up a variable. Sorry. It's up a variable on index one. Right. So that's quite easy, right? You already know this stuff, but the difference is that we get a error. Okay, So why is that? Well, the double object, right, which is this stuff? Variable, right? Does not support D item assignment. Right. So we cannot assign anything to it. So that is why we can't change any values that are sore in detail. All right, so if I run this like this, it will work. Right? So we bring Microsoft, that is this this goat in here, and then we bring Google. All right. So, yeah, you can also come in this one out just to see only the stuff that we are working on. And as you can see, it's it's only Google, all right? And yes. So that's the main difference between temples and list. In topless, you have the same value. You can have saying value multiple times in here. So, for example, in here you type Google, right? And this will also work. Yeah, there is no problem in having same values multiple times. So, for example, if I ask for the 40 value on index free, we will get the same result. Right? Google. All right, so yeah, that's pretty much it for this lecture. The These the doubles works exactly. Same as sets. Only you cannot change the value. All right, 20. Final19 Sets: All right. So what is said while set is another data structure, so basically a collection of variable, same as before. Bar this, Sam, you cannot index the variable. So you cannot use this this thing. All right, So let me just to find a new set by writing, for example, my set. And then when you want to define a new set, you simply type in here the curly brackets, right and out. Simply copy the elements and pays them in here. All right? And then what he can, for example, try to do is try to access some element on some index. Right? So you can take my set and then index, like, for example, zero. And if you try to run this thing, it will get a error. Right? Set. Object does not support indexing, so you cannot do that. And if you try to bring d set, you can do that. So if I run this as you can see, there's apple Google stuff. So why isn't there the other Google? Well, that is because the said does not support duplicates. Okay, so you cannot have two values. Multiple times are like you can have you don't have a error. But if you try to add a Google by second time, it will only be their only ones. All right, So if you know sets from, like, your discreet meth glass or whatever, this should make sense to you, right? If you don't, that that's okay. You should probably get it right. You cannot have same values multiple times in a set, all right? And yes. Oh, that's only one thing. I want to show you another thing that I want to show you. It's some methods that he can do is set. So, for example, if I type in here my set and then I top in here d dot There are a lot of methods that I can use, So let's start with the ad method. What in us? Well, it adds something to descend, right? So, for example, I once at a Microsoft like this. So if I run this right now, you should be able to see Microsoft at the end, right? Yeah. There it ISS. So that's how you can add something. All right, then You can, for example, at multiple values. So, for example, type my set that update and then you can type in there. Yes. Sorry. Then you can type in their a list of values. So for example, I know, um, arrange whatever I didn't know. So something basically anything you want. All right, if I run this, as you can see, there is the orange and some s assess. And another thing that I want to mention is that this list is not ordered. All right. So it doesn't matter in which order the elements are right, as again CD. Microsoft was last when we printed it previous time. And right now at second. Right, So? So the order off elements doesn't matter, all right? That's why de indexing isn't working. Cool. So let me show you another thing, Dad, you can do You can ask for the length of your set so simply by typing Len and then you pass in there. He said, All right, so like this. And if I run, this is should be able to see 6123456 That makes sense. All right. You can do the same stuff with the supple variable, Andy. Let's very But But we will get to it later on. All right. And yes. So, uh, the almost last thing I want to show you is the removed, right? So what if you want to remove something, you can do that, right? You can do my set, my set. And let's say that you want to remove a apple. So, like this, right? So you're basically Addy parentheses, and then you pass. What do you want to remove? And then if you print the set, there shouldn't be any apple. All right. There is no apple. Cool. And once again, as you can see, the orange was somewhere in here, and right now it's first, right? So, yeah, the order it is there's no ordering. All right. But the problem is that if you type in here something that is not in the set So, for example, something like apple to you will get an error. So if I run this, as you can see there, say error Apple to is not in these set, all right? And that's sometimes a kind of bad right? Sometimes you are not sure whether something is in the set or not. For example, if use their right some value than you added, two said you are not sure whether to use the road 10 or five, Right? So, yes. So, Dennett, this this method is kind of bad, right? So in order to solve that, you can use the my set that discard method. Sorry. This card like this and in here, if you type something that is not in the list, you won't get an error. So if I run this as you can see, it works, right? And if I type in here something that is in the list. So, for example, the Ennis assesses, And if I run this, it would delete the Ennis assesses. All right, so it's basically the same as the removed. Only this time, if you are trying to remove something that is not in the list, you will not get a error. All right. So, yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask and I'll see you next time 21. Final20 Advanced Lists: All right. So let's take a look at some advanced south. Did you can do with lists? So, for example, sometimes you want to check whether something is in the list. All right, so you're not sure whether on which index it is, but you would like to know whether a no Google is in the list. So in order to do that, you can, for example, type in here if then you type the Google, right? So some element, right? And then he typed in, and then you type the list, right? So, for example, list variable, as we say, and then you rightly comb. And inside here we rights, for example, brained Yes, yes, whatever. And if I run this program Burns? Yes. Why is that? Because Google is in the list. All right, so that's quite powerful. And another thing. For example, if I type in here Google to which is not in the list, if I run this, it's not bringing anything. All right, so this is false. Cool. So that's one cool thing that you can do with the with the list. Right? So another thing that you can do is ask 40 list length All right. So the length so, like, this length and then you passing their delist. So list of our alright, like this. And if I run this, it should be It says yes, because the Google is in the list, and then it brings for because we have four elements in the list, right? That makes sense. So another thing that you can do is, for example, a pendant, right? So you can add list of our that a bent, right? So what it does? Well, it basically adds an element into delist. So, for example, let's add a a forays. Why not? So if I run this Yeah, I also would like to bring the list. Sorry about it. So print the list there, like this, and if I run this again, we should be able to see a A. It is there. All right, so this is basically adds some elements into the lists, All right? And if you want to insert and element at specific Index, you can also do that. So because this happened, adds it to the end, right? And if you, for example, wants to insert a a element on index one. So you type insert and any type the index. Right. So let's go. It automatically tells you what you what you need to write. So in here you type the index. So, for example, at the beginning, and then we type in there. I don't know, BV v All right, so this one should be first. If I run this program, As you can see, the DVB is first. And then there is the apple Microsoft stuff like that, and it doesn't necessarily have to be only on index zero, you can put it somewhere in the middle. So if I run this Yeah, as you can see, the BVB is in the middle. All right, so that's quite powerful. All right. Another thing that you can do is remove some elements. So, for example, if it's I've been here list var dot removed and you best in their somebody's. So, for example, you want to remove stuff, All right? And if I run this as you can see, the stuff isn't isn't in there, right? Cool. And yeah, Another thing. You may know this is that if I get rid of this slide, right, what if I tap in here? Google would it delete only the first Google or both of them, right, What will happen? So you may want to think about that if I ran the program. As you can see, it deletes only the first Google, the last one stents. All right, so it goes from the beginning off the list and tries to find some tries to find a value that is equal to the value that we passing here, right? If it finds the value, it deletes it and ends, right. It does not go on and on. All right, So another thing that we may want to do is delete some element, right? So, for example, let's say that I know that the apple is on index one and I would like to delete it, right. So, yeah, let's do that. I don't want to change the value to anything, right? I would like to completely delete it from the list. Right. So in order to do that, I simply type in here. Dell is a delete, right? And then I type D list bar on index zero, which is the apple index. Right? And if I run this, the EPO will not be there right in here. We have the effort in here. The apple is not in there because it's deleted. Right? Another thing that we can do is delete the whole list right by writing del List bar without the index. Right, That would lead the whole less so if I printed right, It's this list bar is not defined because we deleted it in here. All right, so I'll just get rid of this stuff. And yes, so and I think that you can do is clear delis, so get rid off everything in there. So if you want to do that for some reason, you can type in here in this tired out clear, and that will get rid off all the elements. So if I run this as you can see, it's just like empty, empty square brackets, right? Because there are no elements because we all delete it, right? Yeah. So that's pretty much it for this lecture. If you have any questions, feel free to ask end al soon. Next time 22. Final21 Advanced Tuples: All right. So let's take a look at more advanced stuff that you can do with double. So, for example, you can do the same stuff as with less. So you can ask whether, for example, epo s indeed apple so is is in the Surrey in the top of variable, right? And then you can bring for example, yes, right? And if I run this as you can see, it says yes. And then it brings the whole supple right and the nothing that you can do a sprint the length using the Len, right, Lang. And there you past deeds up a variable. Right? So same stuff is before. If I run this, you should be able to see four, right? That then makes sense, right? So nothing too interesting yet that right now when we can also do is for example, day led duffel, Right, laddie Dill. So same same stuff as before, right? And if I run this, we get an error because it is not defined because we delayed it. And then we ask 40 variable. Right? So it is like if you delete a file in your computer, you cannot open the file right so, yes, same stuff is before. And then what we can also do is find a index of a of a element, right? So, for example, let me say that I want to find a So let me define a variable called index Off a Stuff. All right, so stuff and we will find the index off stuff. So let's say that we know that stuff. It's somewhere in the top, all right? But when we are not sure at what index, Right, So we want to figure it out. So simply, we talked tough of our then we type dot index and then we passing their d the stuff, all right. And then let me also bring the index so that you can see And if I run this, it's us to and the stuff it's actually on Index to write at Google stuff. All right. So, yeah, these are the cool things that you can do with couples, and that is very much a for this lecture. If you have any questions, feel free to ask and I will see you next time 23. Final22 Set Operations: All right, so let's take a look at more advanced stuff that we can do with sets. So, for example, if you have a glass of discrete math, you probably know, Dad, you can do union and intersection, right and difference. But if you don't, that's okay. So let me just show you how to do that in Typhon. So you simply type my set, then dot and you type in here union and the second set. So my other set, for example, And then if I run this, as you can see, it's as apple saff, Guga and F f f right, which are all the elements that are in both of these lists. So there are no duplicity values right there. Each value is there only one time. But they basically took these two elements from both sets and put them into one. All right. And yes, So another thing that you can do is do the intersection, which is quite similar. And if I run this, you should be able to see what What's the difference, right? The intersection basically takes the elements that are in both of these sets. So the element that is in my said. And it's in the my other set will be in the result, right? But for example, the staff is only in my set about it is not in the other set, so it will not be in the result. And as you can see, it is not right. So there's basically the intersection, and another operation that you can do is the difference. So difference and what it does well with Miranda programs. So we can see. And as you can see, there's only stuff. So what did that? So, for example, in here we have the my set, and it basically takes all the elements for my set that are not in the my other set. All right, so if you, for example, EPO, it's also in the my other set. So it will not be in the result, right? Google Same thing is also in the other set, so it will not be in the result. But stuff is not in the other set. All right, so it will be in the result. And that's why we have only stuff in here. All right, so I think this should make sense. And another thing you can do is ask for whether it is a subset you can do, whether it is a diss Joints said right, But yeah, that's this is more kind of 40 this grade math class than 40 40 by thin glass. Right. And here you can check for all the methods that you can do, right, So simply type dot and then you can check. You have the update union right there. There are a lot of methods, but we will talk about some of them later on in discourse. Right now, the intersections union and the difference is all you need to know. 24. Final23 For Loop: Okay, So what for? Move allows us to do well. In general, a loop allows us to repeat some set of instructions, right? Two all over again. The same code. All right. So Luke, for example, allows us to bring every element from a list. All right, so let's say that we got in here delist companies. And in there we have four companies and we don't want to do these stuff like brand a company's on index, right? Sorry. Companies on in the zero. Right. And print the company on index Juan and so on and so on. Right, That's too much work. What we want to do is go for every element in the company's NIST and for each element, do the same set off instruction. And that means sprint the element, right? So in order to do that, we can simply do that using the four loop. So in order to create a new four roof, you simply write for, then you write, for example, some name of a variable, right? So, for example, see as a company, then you tag Dickie Werth in Write down your i d list. So companies and any right comb right and then same as if condition. You need to have the space in here, and then you do whatever set off instructions you want to do. Okay, So, for example, in our case, we will bring to see Okay, so when I run the code, you should be figure out. You should be able to figure out what see ISS, right? See, is just the de it traitor, right? It stands for every element that is in companies, right? We want to print it. Okay, So for every C, that's the element in companies. We want to print it. As you can see, we go through Apple, Google, Amazon and Netflix. All right, so that's basically a D for Luke. There's not too much about it. And another thing that you can do is, for example, loop through a string. So if you remember in previous lecture, I said that shrink is basically a set off characters, right? So you want to go, for example, character by character in a string. So you can do that. For example, you can do for you can do like X or whatever in the string example, right. And then count. And then we want to, for example, brained only the one character. Okay, so there will be each character on one line. Okay, So if I run this yeah, as you can see example, right. So But that each character is on one line. Okay, Okay. And another thing I want to show you is that you can see these, these variables to see and this ex outside these loops. So, for example, in here, if I decide to print for some reason to see what is in BC variable, I can do that. So simply type in Princey, then Randy program. And as you can see, it says Netflix at the end. Why is that? Well, the last value that was assigned to the sea was the last element that was in the company's list. Right? Which is Netflix? All right. So that's why it's still have the value of Netflix, and you can even check it with the X, right? So if I type in here brains X, it should be equal to E. All right. So if I run this, it says netflix and then e All right, So cool. Right? That's another thing that he can do and yeah, That's pretty much it. 44 loops. You can have once again multiple instructions in here. So, for example, if you want, you can print it multiple times for some reason. Not sure why you would do that bad. Yet in here, the all the characters are doubled, right? Just want to demonstrate that you can have multiple lines of goat in here, right? Right. So the for loop is quite simple. For every something that is in something else, you do something. That was a lot of something so very bad. I hope you understand it. It should kind of make sense because we do that usually in a real life, right? We want to reiterate through some Siri's off off some things. OK, so, yeah, I hope you understand it. If you don't just ask me and I'll see you next time. 25. Final24 Range: all right. Another important thing. 44 loop is the arrange function. So the range function is basically accepting a number, and it returns a sequence of numbers. So, for example, if I don't want to it read through some list or through some string, right? Like we did in previous lecture, I can integrate through some numbers. So, for example, if I type in here four x in range, all right. And then I I said it's a function. So we have a parentheses, and then in inside the parentheses, I passed the perimeter, which means how much how big the ring should be. All right. And then I can, for example, print d X or right. So let's see if I around this program. Let's see what we get at the end. Let me just given this two lines out, so did you can see it better, right? Bad. Yeah. All right. So I'll need to commend this whole thing. Right. We got the problem that the four cycle didn't have any instructions. Okay, so we get an error, right? And yes. So, anyway, in here we, as you can see, we go from 0 to 5. All right. So that's what the range functioned us. You basically can define the range by multiple para meters. Right? So for now, you can do the like if I change it to 10 it would be from zero tonight, right? So that's another thing you can do for the for loop, right? So you can do it more like this. So if you do for every index, right. So, for example, I in the range and the UN's will be defined as the length of companies. Right? So, Len off cos you want to print the company on index I write. So that's more of a for loop that he can see in other programming languages. Right? This this is a nonsense for python. You would like to do it this way. All right. Bad. You can do it like this also. So if I run this, it would bring all the companies. All right, so that's that's more of a how other programming language have implemented D four route. All right, but it is just for to show you all right. Anyway, you can also add into the range function multiple para meters. So, for example, you can define the starting and the ending index. So, for example, if I want to start from one and then and at four, I can do that. Or I told the the I is in the first situation, it's equal to one. Then we do this instruction and we go back up again. All right, then. I is equal to two. We do this instruction and go back up again, all right, that I is equal to free. We do dis instruction and continue with next lines. All right, so I is never equal to four. All right, just to clarify. And another thing you can add is, for example, an increment. So if I, for example, want to only bring d I and let's say that I would I want to start from 10 to 40 and I would like to increment by five. I can do that. All right, so each time we do the instruction, I will be implemented by five. All right, so we will add five to I. So if I run this, it should say, like, 10 15 2025 30 35 but not 40. Because when it's 35 we do the brand and then we add five to I. But I will be 40. And that means this is the end off our range. Right? So we break out of this cycle and continue with lines down below. All right, so that's pretty much it for the range function. So the range function can be used to It's right through numbers, right for Siris of number, sequences of numbers. And yeah, important thing is to know you can define the starting point, the ending point and the increment. By default, you start on zero and increment by one. All right, so this is by default. If you own, it's at this. It's equal like it is. The same thing is typing this thing. All right, range 40. These two, these two calls are to say, All right, so, yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask in. I will see you next time 26. Final25 While: all right, so let's take a look at the while loop. While it is a bit of a different Dendy for group for move usual, it rates throughout, like some sequence right for throughout. Some list for out some set, all right, but the while loop it to rates while some condition is true, so it's basically like an if condition. But only this time. If the condition is true, we it right throughout the whole sequence. Off commands, right? But then we go back up again and check for the condition again. And then we once again it's right for out whole process, and then we go back up again. And once again, it's a rate. It's right until the condition is the wild. The condition is true. All right, Wendy, condition is false. We don't it's right, and we jump at the end and continue with lines down below. So let me show in an example. So if I define a very ever called for example, I and I said it zero I can do this. So while I is, for example, smaller Dan 10 come and then I want to, for example, brained I so print I like this. And then I also want to increment I so and we'll sit. I equal to I bless one. All right. You can also do this thing. So I plus equal one. All right, so right like this. But at that zoo. Never mind that. So you can simply keep it simple and do this thing all right? And then when I run the program, what do you see? You go from 0 to 9. So why is that? Well, computer ghosted his while loop and fingers out. All right. Zero is smaller than 10. So that's quite cool. And he can do some commands. So then he goes to this line, brings I And then he said I was a I plus one. So that means I is now one. All right. And then he goes back up again to this while. And once again, Cech, 40 condition. All right. And I is now one. All right, so I was still smaller. Dentyne. So he brings one that's right in here. You can see what, and once again he increments. I All right. So did we can see to And we go all the way up to night Why can we see 10 in here? All right, well, think about it when I is nine. All right. Computer ghosted his while and checks nine a smaller than 10 right? That's true. That's true. So he prints nine, but then he increments nine. So he s wound to nine. That means I is now 10. So that means when he goes back up to this wild and checks this condition then is no longer smaller than 10 right? So he breaks out of this cycle and continues with instruction down below and earned any All right. And another thing I want to mention is that you can make the condition in the Guadalupe much more complex. Why is that so, for example, let me just define a new variable J call equal to I know my understand. And we can also say, Dad, we want to loop while I smaller, dense n and J is smaller than why. So you can make the condition much more harder, right? This one will not do anything. But if you, for example, will change that to while Jay is bigger than I and said J to, for example, five well illiterate only 25 All right, so 0 to 4. Right. 25 And yes, Why is that? Well, we have the end in here, and J is equal to five. So we are basically looping while I is smaller than five. All right, so, yeah, that's just to demonstrate how D condition can get a bit more complex. Right? You can do that. You can. Any condition you can fit into a If statement, you can fit it into a wild statement. All right. And then it's pretty much it for this lecture. If you have any questions, feel free to ask, and I'll see next time. 27. Final26 Break, Continue: In some cases, we want to break out of a while. Loop before, For example, dis condition is met. So let's say that we are printing the company's all right. So we are going from EPO Road and Google, Amazon and Netflix. All right, but let's say that we first some reason hate Netflix. I don't know why, but we hate it. And we want to stop when we are at Amazon. Right? So Amazon will be the last company that we want to print. All right, so how to do that? For example, there are a couple of ways we can do it, but we can do it also. Why are the brakes statement? So what braked us? Well, it allows us to break out of a cycle. All right. So, for example, we are its rating from Stam stuff, but the condition is still true. All right, so we want to break out when something happens. All right, So we simply tell the computer, okay? I want to break out, no matter what this condition looks like. All right, So if even if this condition is true, the computer will break out of this cycle, okay? So let me just show you. So in here lead to find a if condition. And then let's say the company's on index, I All right. So the company that we are currently at So the element in this list companies that we are currently at is equal to Amazon like this. So if it is equal to Amazon, we would like to break out of this cycle and how to do that. Well, we simply right break. So if I run this and as you can see all right. All right. Let me just come in the east, These two out so that you can see it better. And so like this. And if I run it again, you should be able to see on Lee EPO, Google and Amazon. Why's that? Well, we have the break statement. So how computer evaluates this? Why loop? Well, he starts at zero. OK? Because eyes equal to zero. I still smaller than the length of our companies, right? The length of our companies is equal to four right? In our case. So we print the company, so we print at all. Okay, then we check whether apple is equal to Amazon. It is not so we ignored his line. An increment. I all right. Then we go back up again and it is now equal to one. It is still smaller than four. So everything is alright. We go into this via loop and then we bring the company which right now is Google. And we once again check ready. Google is equal to Amazon. It is not so. We ignored this line and we increments I all right. Then we go back up again. I is still smaller than four, right? It's too because we have Amazon in here. And so we bring dams and out den We check whether Amazon is equal to Amazon and yeah, it is right, it's it Iss So then we break out of the cycle. And another thing is that the I should now be equal to two because this line will not happen. Okay, so if I bring tie like this and if I run this as you can see its ass ever Google Amazon and then to all right because this line will not happen because we break out of this wild loop . So that means we end up at this line 10 all right. So, yeah, That's basically how we can use the brake statement. Another thing I want to mention is that if I put this breaks than statement even above the print so like this what happens? Sorry if I put it deep, bring back brand companies on Index. I like this. So what happens? Will Amazon be printed? Well, it will not because we g o ever Dan Google. All right, Everything is all right, then. We reached Amazon. So Amazon is equal to Amazon, and we break out of this cycle. So these two lines will not happen and will only print I I will still be too All right. But Amazon is not in here as you can see. All right. So, yeah, this is the brake statement. We simply get out off a loop, and it also works in a in a four room. All right, So, for example, if I just delete this thing and decided to go through four companies and inside here again once again, do something similar, So if a C as the company is equal to, for example Google, I want to break out. So break. And as you can see, it should work, So yeah, Yeah, I forgot about come in here. So if I run this again, it says Apple and Google. All right, so the C goes from EPA than it goes to Google, and Google is equal to Google. Right? So we break out and we ignore Amazon and Netflix and continue with these life. And another thing that I want to show you is the continue statement with the counting new statement, we can stop the current iteration and continue with the next one. All right, So, for example, if I put in here, if the company is equal to I don't know, for example, apple or it. So right from the start, we want to continue. So, as I said before we stop the current iteration. So we stop in here and continue with the next one. So we go from from here, we go straight up to this four. All right, So the instructions down below, So that means only the sprint will not happen. So if I run this if I run this, it should say Google, Amazon and Netflix because EPA is skipped. All right? So I can put once again more complex conditions. So or C is equal to, for example, Amazon. So like this. So if I run this again, you should be able to see only Google and Netflix, right? Because these d condition was met two times for one for epa and then for Amazon. All right. And when this condition is true, we skip the arrest, the the remaining part off the four loop. All right, so that means the sprint and we go straight up to this four and continue with the next Salomon. Okay, so that's what continue allows us to do. All right. And another thing I want to show you is that it? This d continue statement works also 40 wife cycles. So if I define, for example, a simple while cycle like I while I is smaller than five, I would like to increment I right. So I plus equal one. And then I would like to check whether I is equal. Let's say to And if it is, I would like to continue, all right? And if it is not, I would like to print so print and then why? All right, So if I run this, you should be able to see while free. 45 All right. And it's exactly what? What do you see? Why is that? Well, we started zero. All right, then we increment. I So I is now one. We check for disk condition. It's false. So we skipped. Discontinue, and we print one. Okay, Then we go back up again and see that one is still smaller than five. Right? So this is true. Sorry. This is true. And then we check 40. Then we increment. I All right. So I is now, too, and we check for this condition, and two is equal to two. So we go out and execute. Discontinue. That means we skip the rest off the loop. All right? So it will not be printed, and we go straight up. And I is now two, okay? And then we continue. So I plus equal one that's free. And this condition is not met, and we print and the same thing happens for four and same thing happens for five. Okay, so yeah, that is pretty much it for this lecture. If you have any questions, feel free to ask and I will see you next time. 28. Final27 Dictionaries: All right, So what is a dictionary? Dictionary is basically something like a list or something like that about inside. We have Paris, and each pair is made up from key and value. All right, so let me just find one dictionary. I think you will understand it better on an example. So dictionary and dictionaries, whatever. Yet And inside here, when we want to define a dictionary, we right curly briquettes and then inside them, rewrite the pairs. All right, so each time we write key and the value of that key. So, for example, key can be something like a brand. All right, so let's go. This one, for example. A items. Okay. And we will have a brand, then we right column and the value 40 key. Okay, So for example, it can be like apple. Okay, then we write comma and only next line we can write, for example, a model. So, like, this model. And then we rides, for example. I know X. Then we writes. I had no year. Okay, You can do whatever he won't write. And inside he rewrite for example, to 19. Okay. And that so then what we can do is, for example, printed so brained de items like this. And if I run this program, you should be able to see all the items. Right? So they're despairs, right? Separated by comma. Okay. All right. But how do you access an item? Okay, how do you do that? Well, do you remember list? And we had the indexing, right? So this thing works similarly. But instead of the index's, we have the keys. Right? So this brand model and year So, for example, if I to find a new variable called temp and indeed 10 variable, I want to store the value of a item. And in their for example, D Brent Okay, So devalued that is in the brand, their ok, which should be apple. And then I can print it like this. So if I run this as you can see, it burns apple. Right? Because apple is the value of the pair where the key is Brende. Okay. And where is the same? But for if I commend this line out and right in here, d get so if I tap in, he items that get And then I passed the brand so like this. OK, and inside here we plastic brand. And if I run this, it still says apple. Okay, so these two are the same. Okay, cool. And not a thing that you can do is, for example, change a value for particular bear. Okay, So for example, let me say that I want to change the year 2 to 20. So if I, for example, type in here the items and then in square brackets I tap in there the year and then I assigned a new value so to 20 like this. And then if I want to bring deep hole dictionary If I run this file, as you can see, it says through 20 Ok, 2020. So it works basically the same way as a less only this time instead of indexes, we have the names. So the keys. Okay, so another thing that we can do is loop through a dictionary. So, for example, if I want to define a new four room and inside here, I want to low loop through every item in items so basically through every key and items in the dictionary items, and I want to bring the key, So if I type in here. Print. Exe if I run this so round Bite on file. And as you can see, it says brand model and year. So the X in items basically means go for every key in the dictionary items. Okay, So how do we get the values? How do you how to do that? Well, we can't index it. So in here I tacked items, and then on index, we write key. Right? So the index is key, okay? And if I run this again, it should say Apple X and 2020. Okay, so these are the values, OK? About still, if you want to do it differently, as you can do that simply in here type items that values and then Bren theses. And that means we go for every value that is in the items dictionary. So that means it'll x and 2020 right? Because we change it in here. So if I get rid of this stuff and run this, it says the same thing as before. Okay. Cool. Okay, that's quite cool, right? You gotta admit bar I was still like to go fruity G and the value at the same time, right? So I would like to have something like X and why in here And then I would like to go through every pair. So in the X, I would have the key and India, I I would have the value. Okay, So how did I do that? Well, you can also do that simply in here type items. So items that items, for example, with me, Just rename this to item. Okay, So that it looks quite better, right? You dive dot items and this will return a pyre. So if I, for example, then type in here print X and why, like this? So I can do that. So if I run us as you can see, it says brand Ethel, Model X and year 2020. So, yeah, that's another thing I maybe didn't mention. You can print multiple variables at the same time using the comma in here, right, As you probably noticed. All right. So another thing that you can do is check whether something is a key in the dictionary. How do you that simply, for example, by writing if and then, for example, Tide brand this in the dictionary, So that means item, right? Dan You're right. Comb And for example, we bring something like Yes, Yes. Sorry. Yes. And if I run this as you can see, it says yes. Right? Because brand is obviously in the items, right? It's right here. Okay. And so it's basically the same s as if we when we checked whether a element is enlist, right? Only the sign. We are checking whether a brand is in dictionary. Ok, All right. But what if I want to check whether a value is in the dictionary? Right. So right now we are checking only for the key, but what the value? Well, I can also do that. So for example, if I want to check whether X is in the dictionary, I can type in here if X is in item dot Values so same stuff as before. So the item that values basically allows us to access a list of values that are in the dictionary. Ok, I hope that makes sense. So then if I renders again, you should be able to see the brand and yes, Okay. So yeah, cool. But then you might think What if I want to add a new item? Okay, so What if I want to add a new pair to this item dictionary? Well, I can do that. For example, simply by writing in here the item than the square brackets and, for example, something that it's not in the dictionary. So something like Bryce. Okay. And I can set the price to like June 99 1099. Yeah, whatever. So if I now, Randy program, you should be able to see the price in there right at the end. There is price. Cool, right? And same goes for the leading. So remember how we deleted an element from a list? The same thing goes for dictionaries. So if I want to delete, for example, a item where the key ISS I know year, right? So I wanted the lead the year. I can do that simply by writing like this, and and I will bring the items again. Sorry. Item so that you can see it. And if I run it as you can see, the 1st 1 that's this sprint online. Nine prints, D price and year bad. The second print deletes the year. Okay, we cannot see in any year in here. Okay, Cool. And dan is pretty much it for this lecture. 29. Final28 Creating New File: All right. Files are used in pretty much every application, right. You have some text editor right again. Save the fire, Luke. And open the file. You have, like, a I have no video player, right? You open a video file, right? So pretty much every application uses files in some sore, so it is important to know how to do that. So, first of all, we have the open function and what this function does. Well, it opens a file for you so that you can right into it and that you can read from it. Okay. And so it takes view para meters like file, which is just a bath to your file. So, for example, something like, see, you know, it can be absolute bath. So some folders in here, or it can be also a relative path. So when you run your application at the application is located in some folder, right? And if you use a relative bath, you basically can create a file in the location where your executed will file is running. Okay, so So when Where the location off your file off your program is. Okay. So, for example, let me show you that. So, as you can see, the files is in some directory called Code. Okay, that I have opened in here. And if I, for example, want to create a new file and then write something into it, I can do that. So, for example, in here, right, I've the name of my file and the name of my file on Lee. I don't necessarily have to ride the path in front of it. Right. So that's the difference between the absolute bath, where you need to write everything from the sea and so on to the relative bath, Right? Very right. Only the name so mild textile, that txt, for example. And then you write the mode. So basically, and here you define what do you want to do with the file? So there are a couple of options. The 1st 1 is that you want to create the file, which is X. Okay. So the first leather sense for what do you want to do with the file? You can open it. You can read from it. You can write to it over you. Can a pen defile? Okay. And the second leather stands for the dye profile. So far, we have two types. The 1st 1 is a text file. So, for example, something like just a text file. You can think of it as a file. Did you create in your word? Okay, So are in any other text editor, or you have a binary file. Which is, for example, a image. Right? Image is a binary file. And yes, So, for example, let's say that we want to create a text file. So then we type in here. DT. Okay. And if you want a binary file, we will type in here, Be all right. So this one will be text file you also detest is a default option. All right, so you don't necessarily have to write it in here, OK? But I will just leave it in there. And obviously, right now, we simply opened a file, but we have no way to work with it, right? We didn't store it anywhere in our memory. So we will create a new variable called, for example, F, and we'll assign it to the value of the opened file. Okay. And then we can do all kinds of stuff. So, for example, we can right into the file. So f. Dodd. Right? And then we passed in there some strength. So just few ace. Okay. And if I, for example, Runde program right now, it nothing is printed. Right? But as you may notice, in here, it's my text file, all right? And so this this file did we just created, and if I double click it, it will open up in my editor. And as you can see, there are the few ace. Okay, so yeah, that's quite cool, right? It's simple as that. You simply is the open method in order to open the file. Then you define the moat. So basically what you want to do with the file, and then you can use all kinds of fancy stuff in here. All right. So I will talk more about it in the following lectures. 30. Final29 Write, Append: All right. So in his lecture, I will talk about how you can right into a file or how you can a band a file. So if you are a natural, what that means so right basically means that you open a file. Then if you want to write, you basically delete all the content that waas in the file before you open it. Okay, so in some cases, you want there. But in most cases, you would like to extend defile, right? And right at the end of the current file, which means happened, right? So you basically opened the file and you start riding behind the current content. Okay, so yes. So let me show you how you can do that. First of all, in here as against see, we defined the mode, right. As you learn in previous lecture, DT is default, so we don't necessarily have to write it in there. And the X stands for create a new file. And what I forgot to mention in the previous lecture is that when you try and open up a new file that it's already created, So, for example, idol type in here is something that I want to write like whatever. Right? Okay, so currently this a 80 file, but my point is dead. I already created the file. Right. As you can see in here, it says a bar. I want to create it again with this X. So what will happen? Well, if I run this file, I will get an error. Right? File exists. Error. So what it means Well, you can on Lee use this ex if the file doesn't exist, right? If this file exists, you cannot use the X. You will get an error if the file exists. So yeah, bad. Let's go to the writing. So if you want to write, you simply tap w like this. And if I run this program right now and works just fine And if I opened the file, as you can see, it's over O d a A. And rode the stuff that we added in there. Okay, so if I go back to files, as you can see, there is just d d f d d d So if I, for example, change it once again and around this again it should be changed once again. So if I go to this file. As you can see, it's J J J. All right, cool. So another thing that I want to mention is that you can write multiple times. So, for example, in here, I would like to also write something, and yeah, so if I run this, the file is changed, and as you can see, it says JJ, JJ and then G all right, so, yeah. So now you may ask, What if I want to end the line? All right. So how do you do that? Well, you can use one of the escape sequence. So for example, this one, so this one will end the line. All right. So, for example, if I add some text down here and run the program, this J j. J will be on the next line. So if I look at defiled, as you can see it, it's on the next line, and you can do much more stuff. So, for example, you can use a tap, right? So you can type a tip inside here. So if I run this right, as you can see, there is a space. And between these two, all right. So cool. That's what you want to do. But let's say that I would like to a bendy file, right? So the thing is that I always over I d file when I run the program. So let's say that I want to simply open the file and then start riding at the end of the file, right? So simply extend defile. And in order to do that, I simple changes, Right? So the w two a and as he happens, and if I run this as you can see, it worse is fine. So you use the same methods. And when I opened the file, as it can see its start typing from here. All right. So yes. So this is the lines that we are that we wrote when we execute the you file. All right. So, for example, if I change this only to G, And if I run this program again, as you can see, it's these four G's again. So if I run this one's again so that you are absolutely sure that I'm not lying Yeah, there are another four G's. All right, so, yeah, that basically it keeps the file the same and then types something other to the end of it. All right. So, yeah, That's basically how you can write something into a file 31. Final30 Read File: All right. So let me show you how we can read a file. So usually you write something into a file and save it. Right? So, as you can see, we have the file in here, but then you want to open it up and read the actual content. So in order to do that, you need to specify the perimeter. Right? So inside here, you type air as a read, all right? And then you can use the read function in order to read the file. So, for example, if I want to print it out, I can print it out using a f Dodd reid and then parentheses. And if I run this program, as you can see, it brings the whole content off the file. Right. Okay. They are the same. So cool. Right? So another thing that you can do is specify the number off characters that you want to read . So, for example, let's say that I want to read only the 1st 4 characters. So that means these four jays and I can simply do that simply by typing in here the sides off the characters that I want to read. So four and if I run this, as you can see, there's only D j j j gay. All right, so quite cool, Right? And another thing that you can do is three d file line by line. All right, So instead of this read, you can right in here, eh? Read lines. So read life and yeah, parenthesis. And if I run this as you can see, there is the first line printed, right? So that is quite cool. And you can use this method multiple times. So, for example, if I read line again, I will read the second line. All right, So if I run this, as you can see, there is the first line. All right, so in here is the actual content of the fire arts. So that's the first line and the second line. Have more G's in there. All right. And yes. So that this one And if I want to read the entire file, I can put it there. Differed, read file statement. And if I run this sorry read line, and if I run this as you can see, there's the last line. Cool. So another thing that he can do is simply Gil fruity file. Where? A loop. So as you might remember, we learned about the four loop. Right? So, for example, in here you can have something like four line in the F. All right, I want to print it. So I would like to print every line like this. So if I delete this stuff and run, this program has against see, it is exactly the same. All right, so this this is the same s before the free re line statements, so yeah, that's quite cool, right? He can read a file. You can do a writing. You can. You can. Right now. You can basically work with vials. So, yeah, if you have any questions, feel for you to ask, and I will see you next time. 32. Final31 Deleting Files and Directories: All right. So you know how to open how to create and how to read and how to write. All right, that you don't know how to delete. So how do you delete a file? Well, the leaning is a bit harder. So for the opening and stuff like Dad, we only dealt with the open function, right? So it was quite simple. Only in here we defined what we want to actually do with the file. Right? So the deleting is not so easy, but it is also not complicated. So let me show you. First of all, when you want to delete something, you need the help of your operating system. All right. And in order to add the the functionality, right, the some of the functionality of your operating system, you need to import the operating system. So simply type in here in Port os and what that means. Well, basically does. Lying tells the computer Hey, I would like to use the OS module, right? So, yeah. Then you can use all the modules from the OS. So for example, os dot Then for example, remove. And then he specified the name of the file. So for example, the my text file. All right, so let's remove the file that we just created. So my story text file dot t X c. And if I run this, it rants. Andy Finals deleted. Right? So, yeah, that's quite cool. Right? So that's how you can remove a file. And if I, for example, wants to, I will just create this file again. So create. And then we also need to, for example, write something in there, so right and ever let's write something bad. Yes. So if I create sorry, creators where X So if I create the new file and again I can do that right, the fire should be created. Theodore, Otis. And then I would like to remove it. But I would like to first of all, check whether the file actually exists. Right? So you that's usually what you want to do. You want to check Greta Pfeil exist, And then, if it exists, do you want to delete it? Right. But if you, for example, if I type in here something that does not exist or I to some file that is not existing, I would get an error, right? So I need to check for this. And in order to check for it, you can simply type in here, for example. And if statements. So if os dot bath. Right, So what do you want to check? Whether it exists. So you type bath exists, and then you type in here the path. So, for example, the my text file. So my sex file that sexy? All right, so this one will check whether defile exists, and if it exists, we would like to remove it, All right? And if it does not, we can, for example, for in something so else we would like to Oh, sorry. Else we would like to print a the file dust not exist. All right, so if I run this file again, it will work, right? So yes, Sorry. I want I'm currently I'm creating a file that is already being created. Right? So I will come in these two lines out and run it again. And as you can see with deleted defile And right now, why? Why did happen? Well, because the file existed, right? But this time the file does not exist. So what happens if I run this again? It will bring. Defile does not exist. Okay, So in order to delete a file, you need T. O s support. So you need to in 40 always module, and then you can, for example, check whether defile exists. If it if it does, you can remove it. If it doesn't, you can bring something to the user to let him know that you cannot delete the file. And another thing that you can delete is the directory, right? So, for example, as you can see in here, I have the temp directory. So let's really that simple tapping here os then dot And then you want to delete the directory Or, in other words, you want to remove the directory. And by short, you type arm is a remove, and then Dyer is a directory, and then you type the name. So in this case, it's the story temp, not test bodied Sam directory, as you can see in here. And if I run this program again, it should delete the directory. And as you can see, it is the legal right, so that's quite cool. That's how you can delete files and directories. And yet, if you have any questions, feel free to ask, and I'll see you next time 33. Final32 Try Except Finally: So, as you know, from previous lecture, if you're working with files, some Eric can occur. Right? So, for example, you want to create a file that already exists, right? Or something like that, You get an error. So you would like to try something out. So you would like to try to create the file. But if the fire already exists, you would. You don't want to end the application, right? You would just maybe you want to just bring something or you just want to work with the file. That's right. Do you want to, for example, reedy file only or whatever, Right. So you don't want the application to crash where some error. So in order to do that in order to try to do something, you used the try statements. So simply typing Verity, try then d come. And inside there, you type all these statements that you want to try it. So basically in here will be decode. That can result in some error. Okay, So for example, the open off the foul. So for example, in here I will say I've assessed dot t x c and in their arrival type that I want to create the file. And then I would, for example, one to write something in there, and that can be just whatever. Right. But when I am working with these files, the Eric can occur. So what happens if error occurs? Well, in here we have the except clause to handle that. So inside year, we basically tab decode that we want to execute if an error occurs when we try to do this, these statements All right, So, for example, in here we can just friend a error, okay or whatever, right? So if I run this program right now, it should just work, right, Because the file does not exist. So, yeah, there there is a new file called Test, but if I run this again, all right, So if I run this again, we get this Arum and Dennis is one type off heritage you can get, right. You can also get another error. So, for example, if you type in there a variable that is not that does not exist, right? So, for example, we don't have any variables in here. So if I, for example, ones of print I know and eggs, the X does not exist, right? It's not any very ever in here, so we will once again get an error. So if I run this, as you can see, there is the error. All right, That. So if I, for example, come and these soon lines out, right, we still get the air. All right, But how do we decide which error took place? Well, we can do that. So we would like to, for example, handled this kind of name error differently. Dandy file opening error. All right. And that makes sense, right? Sometimes you want to handle different errors differently. So how do you do that? Well, simply inside behind you accept you type the name of the error that you want to handle in this fiasco. All right, So, for example, it can be a name error. All right, So if I run this again, we get the error. And I can, for example, type in here D name error so that you can see it. All right. And then you can define another, except for example, 40 file. So if I type in here, the except and then like file already exists. Yes. So file already exists. Error and then I can print the no file exists. And if I run this, it says file exists. So why is that? Why, Why? There's no deal by there's not printed the name error. Well, computer evaluates this block and like this, so he goes and sees destroyed. So he says, All right, I can try to self. And if something happens, I call these two, okay. And so he tries to open the file, All right? And you see that the file already existed, so he raised an exception. All right, so basically, exception means that something happened that was not planned. All right? And then the exception name is file exists error. All right, So he looks at these accepts and sees that this one is for name error, and this one is for file exists error. So he calls this one and executes the lines inside here. All right, so, yeah, that's how you can define the accept. And for example, if you want to just to find a general. Except Brad, you can do that simply like this. So, except and inside here again. For example, friend. Just the error. All right. So, for example, you don't know what causes the error body know that he ever happened, right? So if I run this as you can see, there's only the file exists. So this is basically, like an if statement, right? It executes only the body off this except right. And then it's gives the accepts below. All right, cool. And another thing that you may want to do is use the finalist statement. So what it means? Well, if you try something out, no matter whether dead works or redder, that ends up in a exception, right? So whether you get an error, no matter what you, it will always execute some part off code. So, for example, that is useful if you want to close a file, right. So no men already you can read or you cannot read. You want to close the file so that other programs can use it, right? So that's usually in the finally statements. So inside year, you tidy finally and then simply d come. And in there you can define what you want to do. At the end of this, try close, right. So you usually want to, for example, closed the file all right, and Yeah. You also need to be careful about whether the f is not undefined. So, for example, if I run this program right now, it will be not defined. Right? Why is that? Well, because we didn't open anything, right? This open call caused a exception. All right, so we can, for example, inside here used the right so that we won't right into the desk file. And if I run this again, Edwards this fine. Only this time we get the name error. But we closed the file. So if I, for example, brings in here something like and off try right, I can do that. So if I run this as you can see, it is executed. Even dough. We get the name error inside here. Okay, So and that's another thing that I want to mention Is that the error? This exception handled the error de name error. Okay. So that it actually works. And yes, So another thing is that if I the lead this line, this gold will work just fine. All right? So none of these exception will take place, and we will still execute. He finally. So if I run this as you can see. It still says, End of try. And so that means it closed the program. It close the file also, right? So, yeah, this is basically the try, except close. And they're in here. You can do all kinds of fences stuff. I recommend using this a lot. You can handle a errors. So sometimes in their program, you just you are just not sure whether somebody is using some the file that you want to read from. All right. So you need to be an able to handle the error, that somebody is using it. And you can do that where I d try and accept. Close. All right. So, yeah. If you have any questions, feel free to ask, and I will see you next time. 34. Final33 Functions: So how do you use functions in biting? Well, first of all, you need to define a function, right? So you type in here defines and then the name of the function. So, for example, in my function, sorry. Like this. And then parentheses. All right. And then comma. And inside here you tapped all the instructions that do you want to execute. So, for example, are no brains and function called All right. Okay. Like this. And yes. So then what I can do is, for example, call the function. So this is basically how we can define a function. It's not so complicated. Right? So you have the key ward. Then you have the name brand theses where you define the arguments, right? So we will get to it later on, then staying step is before, right? There is the debt, as you can see and s. So then I can, for example, Cody function. So my function and parentheses, and that's how you call a function. So if I run this as you can see, it's this function call. And the cool thing is that I can call in multiple times. So, for example, if I decided I want to call it for second time. I can do that and there will be to function called. Right. So that's one And their suit. So yeah, that's how you can define a function. And that's how you call a function pretty cool, right? So not a thing that you can do is, for example, passed an argument and Barham either. So, for example, and let's say that you're going to pass a X. All right. And then we would like to print it with the function called. Okay, so in here we can, Then. So this is basically the perimeter, and we can refer in the body off the function to despair meter. All right. And how do we define what? Well, you will be stored and despair meter while we pass it in here. OK, so whatever we type in here will be stored as a value off this x or red, and you can type in whatever function called one all right, and I will call it twice to read. And if I run this as you can see, the output changed depending on whatever we passed in here, All right? And it makes sense, right So this this para meter is blinded as a value off the X and the X is basically a variable. All right, nothing more. So this is basically a very ever, and then we print the value. All right, So, as you can see, it's his one. And then it's us to in here, so yeah, that's quite cool, right? But another quite cool thing that we can do is define a default value for the X. So, for example, I can assign it to, let's say zero. All right, And why did can be useful. Well, sometimes we don't want to define all of the Vera meters, and we would like to use some default value. Right? So something like this, and then what we can do is scold, eat my function without any para meters, and this default value will be set as a X. All right. But if we best a per meter, this default value will be override by ex. All right, So if I run this, you should be able to see function called one. Why is that? While we best one inside here. So it deleted the zero and set it as a value of X and then reprinted right singles for two . But then we didn't best any value. And since we have the zero in here, we didn't get an error. And the value of X is equal to zero. Quite cool, right? So if I remove this thing and run this program, let's see what happens. Well, we get an error, right? Because we have a required argument, X and there is no value in here. All right, but if we said it to the default value, we are all right, Cool. 35. Final34 Functions 2: All right. So in the previous lecture, we talked about how you can define a function right and how you can call it bar. We didn't actually talk about the d function can return some out foot. All right, so let's talk about it now. So let me just find a new function that will be just out function. Okay, whatever. And it doesn't necessarily have to accept any arguments, and then it can, for example, choose return 10. All right? And that's it. That's it. So if I, for example right now, want to friend the result off our function, right, So off the our function calls, So remember the parentheses. When we want to call a function, I can run the program. And it's a sen. Why's that? Well, we call dysfunction, and it returned 10 as a result of the function. Okay, So instead of this, our function, it's actually saying 10. All right? And yeah, that then get printed. All right, so that's not a rocket signs you can, for example, at and Germany's air in here and, for example, return like 10 times X. And in here you can, for example, toe best five so if I run this, it says 50 right? And if I, for example, called, is one again with a free Yeah, whatever. And I run it again. It's his 50 and 30. All right, so yet is how you can define a output of a function. And another cool thing that you can do is, for example, do a wrenching and yeah, so didn't show you an example. You can do, For example, if X is equal to zero, we're going to I had no print a ever for some reason. And then we would like to return zero okay, or just one whatever. And yet and in other cases. So in other cases else we would like to return the 10 times X. Okay, So I'm not sure why you would do that. For example, you need the function to return a positive number that is greater than zero. All right, so, yeah, might be that bar anyway, So that should be a different condition, by the way, But never mind. So if I run this, what happens? Well, five. It's all right. Well, the X is five, so five is greater than zero, and that means we return 50. All right, singles for free. But then we called with zero. That means this condition is true. So we print error, as you can see in here, and then we return one. So as you can see this one in here, So, yes. So that's the D one is placed instead of this function call. Right. And another thing I want to mention is what happens when I do it like this? What will be do result off the last function call. So let me just talk you for it before I randy code. So we pass in their zero. All right, so x zero. So that means this condition is true, right? And then we print the error, and then we return one, but then underneath, we counting you with instructions underneath, right? Or we should bar. Actually, no. Right. We return the one and that's the end of the function. So this is like a break statement from a loop. Only this time the return breaks out off the whole function. All right, so any instructions underneath the return statement will not be executed. Okay, so it will be just exactly the same as before. Okay? As you can see the error than one. And this thing was not executed. All right, so it's just returned one and placed one instead of dysfunction call. And then do you want to get printed? All right. So, yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask, and I'll see you next time. 36. Final35 Recursion: all right. Gas in the lecture, things will get a bit more complicated. The girls, we will talk about something called Rikers Asian, and this is one of the main subject off a computer science bar. It's quite hard to understand for the beginners. All right, so try your best, but, you know, if you don't get it, it's It's okay. Like I also get a lot of problems understanding Rikers in when I started programming. All right, so it's OK if you don't understand, so, yeah, let me just to find a factorial function. So the example that I am going to show records and on is a factorial off. And so you probably notice from your meth glass where you have, like, the basically the factory off N is equal to end times and the minus one all the way down right times and minus two. All right, and then all the way down to one. All right. So, for example, the factorial off factory, or all four would be equal to free. Sorry for times free times, two times one. All right, so this will be the result. And this is great for Rikers in because what we are doing is actually calling the factory over four times the factory or off n minus one right off four miners, one which means free. So, yeah, let me just defined the function. So factory or off. And and then what do you want to do? Well, we end the line, so the ending condition is a n equal to what? Right? So if an is equal to one, we end the algorithm and return one. All right, But if it is not, we return the factory. Sorry, we return the end times factorial off and minus one. Right, Because that's what we have in here. Factory or four is actually equal. Right? So let me just write it in here. The factory or four is actually equal to four, four times the factorial off free. Why is that? Well, because factory off free is equal. You wouldn't get that that free times factory or off to and factory off to. You probably get it by now. But I'm just going to write it all way to one is equal to two times factory or off one. And then when we call the Factorial with one, we get the result of one, right, because the end is equal to one. So that means this condition is true. And will you return one? All right, So what happens then? Well, right now, when we compute the factory off to companies or doesn't know what the factory off one looks like, right? He only knows that this is a function co. So that means this this is the factory or one in this example, right? So But now, by now he knows that it returned one, right? So he simply overrides this F one with one, all right, and then do the same thing with the factory off to right now. He he knows that he have two times one in here. So he knows the defector off to is to write. So he writes instead of this factory off to two. And then he knows what defector or free looks like. Because we have free times too. Which means six, right? So he just plays this six instead of this function, call, right. And then he get, like, four times six, which is 24 I guess. And that's the result. Or factory or four. All right. So if I run it so that you believe me. So print factorial off four. It should say 24. So if I Randa's as you can see, it's us for 24. So, yeah, just the computer of various this thing. Same thing as a human, as I wrote in here. So factory or four, which means and is equal to four. We go to this condition at this false. So we return four times the factorial off four minus one. So that an inspector or free. So that's exactly what I wrote in here, right? Yeah. And then computer would like to return a number, right? But computer doesn't know what the factory off free looks like, right? So he first needs to compute the factory off free before he returns to yourself. All right, so this is this is really important. He needs to compute defect, aerial of free before he returns. The whole result. All right? And that makes sense. So that means he called this factorial functions with free. And what happens in here well free is not equal to one. So we return free times, factory off free miners one. So that means factory off too. And That's exactly what I wrote in here. Right? And once again, same thing. Computer doesn't know what the factory off to looks like. He only knows that this is a function call. So he needs to compute first computer refectory off to, and then he can return to U Haul value. Right. So then he calls defector over to. And as you can see, two is different than one. And once again, he returns to times factorial off to minus one, which is factory off one. So that's exactly what is wrote in here. All right. And then he calls the factorial with one. And as you can see, the N is equal to one. So one is equal to one, so he can simply return one as a result. All right? And then the computer knows whatis factory or of one Looks like it's one. Right. So, yeah, then then he starts to figure out what these results are, and he can finally give me the final number. So yeah, that's do your incursion if you don't understand it. Exactly. That's OK, but yeah, at least try our best. Maybe watch the video again. And if you still don't get it may be asked me a question and yes, I will do my best to explain it to. So yeah, that's very much it. 37. Final36 Recursion Debugging: All right. So end his lecture. I will go a bit more through. How do you occurs in works and what we will do a step d program. So I will put a break point in here. So that means you can put a break point when you click somewhere in here. And as you can see, the red button stance for the break point. Red circle. Sorry. And yes. So that means when the coat goes to this line, it will stop. And I can take a look at the value off and and everything. All right? So, yeah, And if you understand recordation or if you think you understand Ryker Shin, I still recommend you at least watch a bit off this video so that you are absolutely sure that you understand it. All right. So, yeah, simply put a break point somewhere in here or the on the line 17 and then press F five. So what will happen? Well, computer, will Randy program bar As soon as you reach the line 17 he will stab the execution, as you can see right now. All right, so the program just stopped and I can take a look how d variables looks like and everything that is happening in the program, all right? And I can step the line lined by wine. All right, so right now, as you can see, we are on the line 17 and it also tells me that an is equal to four. You can also figured it out. If you have over the end, it says four, right? And yes. So if you have over any variable, it will tell you that the value off the very ever is equal to something. All right, so that's quite useful. So right now the end is four. And that makes sense because we call the factory or with four. Right. So the end is equal to four, right? And so this condition for is equal to one s false, right? So if you want to step into the next instructions, you can do that by this button. And as you can see, we jumped inside here because we have the else branch. And since this condition, since this condition was false, we get to this line Cool. So, yeah, inside here, as you can see and it's still for and we call, So we trying to multiply the end by the value off factory or off n minus one. So that means free, right? Exactly what I wrote in here. And yes, So another thing that you can do is simply step over. All right? And that means if you click on this this button in here, it will basically returned the whole result off this function, and it will return just 24. But we don't want that. We would like to see How do you function? Call ends up. All right. So you simply click on this step into that means stepped into the function call. All right? And we'll see how the function Cole looks like. So as he can see and a sequel to free. And we get once again to the slide. And then, as you can see, free is not equal to one. So we step again and we reach this line once again. So we are returning free times the factory or off free, minus one. So that's exactly what I wrote in here. Right? Free. Minus one s, too. So if I want against sip into T function, I can see that and is now too So we are calling the factory off, too, because computer needs to compute the factorial of to before he can return the whole result . Right? So he goes like, free times sound function call, and he figures out all right, But I need a integer value, right? I cannot multiply a number by a function call. What would be the result of that, right? So he caused the function and waits till the function returns value. All right, so, yes. So that's the function call. And right now the end is too. So there's different. So we can once against step to the next line. And as you can see, the returns two times two minus one. So factorial off one. All right. And if I step in here runs again and is now well, so that means this condition is true. So if I step in, we return. What? All right, So we stopped the Rikers in. So this is the ending condition off the rickerson and we stopped. We stopped your incursion, and now we're turned a value. All right, So what we are going to do now is step out of dysfunction, So yeah, that basically it takes us two d function call. All right, so two D plays very function Got invoked. All right, Wendy. Function get called. So that means this place. Right? So if I click on this arrow up, we get to this point. And in year, as you can see, if I have over it, it shows nothing. Bar the This is basically one all right, because we were turned one. All right. And then we have an equal to two. So we are returning to times one, which is two. And if I step out again, as you can see, N is free, and we are multiplying it by two. Right? So if I step up again and is four and we are multiplying it by six, right. So that's this. This is a six. And if I step up again, I get to this point and in here, I finally got the results. If I step again, doesn't matter what I click. I get the final result of the program, which is 24 So yeah, That's basically how you can debug defect a really, in order to understand it. The most important thing is when never dairy safe function can call itself right, as you probably figure out that whenever there's a function, call the computer rates until he gets the final result off that function call. So if it's still don't understand it, that's OK. You maybe need to do a few recursive function to kind of get used to the idea of a function calling itself. It's not natural for people to think about us this way. All right, Bad? Yeah, that's pretty much it for this video. If you have any questions, feel free to ask, and I will see you next time. 38. Final38 Lambda Expressions 2: All right. So in previous lecture, I touched on something dead. You maybe not even noticed. And that is the Lambda. Expression is basically a value, right. We can assign it to a variable, and that's really powerful. So let me show you an example where death can be useful. So, for example, I will define a new function called Multiply by and in here will be an end. All right. And then it will just return a lambda expression. So, lamb, the expression will be returned as a value. And it will take, for example, and X, and the result will be X times. And so right now, what do you might think is a no d n? Whatever is happening in here, I want only the end. Cool and sir, and yes. So what you might think now is how do we get to the X inside here? Right. The X doesn't have any value. You get that. We, for example, called the multiply by multiplied by with, for example, free or red yet so the end will be equal to free. And then we return a lambda expression that we don't know the X, so there will be no value at well in here when we defined, um, the expression before, As you may know, this, for example, the name also doesn't have a value, right? It basically only stores the function into a variable. And same things happened in here. So we can, for example, store this result. So does lambda Expressions into a variable. So, for example, a temp, or like, multiply by free, all right. And I can set it is a value off this. And then what I can do is involved this lambda expression. So the result off this is basically this lamb, the expression with free instead of an and then I can multiply it by free. So I can use this very ever to invoke a D Lambda Expressions. Same thing as we did in here. All right, so I can, for example, do like brains a multiply by free, called with 10. So the result should be 30 all right? And I get an error and I forget on government here, So if I run this again yeah, it's his 30. Yeah. So why is Dad? Well, this one will be a bit more interesting, So let me just put a break point in here to see. Well, I'm not sure whether we should will be able to see it. But let's try it. And if I press f five in order to run D d bugger in here If I hover over the multiply by free, it shows nothing, Right? So that's quite bad that in here it is multiplied by is an expression, and X is a under expression. And all right, so this one will be a bit harder to explain. We killed the multiply by free function with free. All right, So, Dad, we get a London expression that says X and 40 X It returns x times free. All right. And that is soar into the multiply by free variable so they multiply by free variable is equal to this valley. And then we basically invoke this love the expression with 10. So we get X is equal to 10 and we were turned 10 times free. All right, So cool thing is that you can do this multiple times, and you can, for example, to multiply by five. Then you pass in their five and then you can also print a multiply by 5 40 10 So if I run this as you can see, it says 30 and then 50. Why's that? Well, this is a function coal, and the multiply by five looks differently. The Lambda expression doesn't have free at the end because N is equal to five. Right, as you can see in here, So N is equal to five. So instead of this, free this multiply by five. Have a five in here. All right, and then we simply call it with 10. So we execute this lambda expression with 10. So that means then 10 times five. And that's 50. So, yeah, this is a really powerful tool, Dad you can use. And if you have any questions, feel free to ask, and I will see you next time. 39. Final39 Modules: All right, So what is a model? Well, module is basically a library that he can use. So, for example, let's say that you define a file called functions dot by thin. And in here you have a few function. So my function out function and factorial, Okay? And you would like to use this file in your other file. All right. And in the other file, for example, modules that p I you would like to call, for example, the factorial functions. All right, So how do you do that? Well, you first of all, import the bison file the functions file, and you simply type in here the functions like this saying, Simple. Is that all right? And then you can invoke any function from the functions file. All right, so from this file And how do you do that? You can simply, for example, Brent. The result Off functions Dodd pictorial. As you can see, it already has suggested me all of the functions that are in dysfunction file. So I will use the factorial, and I will passing therefore, for example. So if I run this, as you can see, it's is 24 right? So Why is that? What? What happened in here? Well, we just called the factorial functions from this file from this. So dysfunction gets gold with four, right? And yes, so that's quite useful. You can import all of the files that you already defined. You can define a library. So you Then it is important to, for example, a functions that deals with, I know with some part of your application in one file and then in other file, you use these functions that you defined in there. So yes, so that it's important when you are creating some kind of a more complex application. Yet that then you probably want to use you want to split the application into multiple files, All right. And then you can import it as a library So you can. Another thing that you can do is rename it so you use the s a keyword and inside to hear you can do, for example, a f and any call it just like Oh, sorry, it just like this. So f that factorial. So if I run this again, as you can see, it just works same ways before. But this time, if I type in here. The functions. We will get an error. So if I run this as you can see, the functions is not defined because we were named the functions to f. All right. So simply type f in here and everything with the word just five. Yeah, and another thing that you can do is import the system library. So system module. So this time we imported a functions from our file that we define that a lot of times we want to import other functions, but from a file that somebody else created, right? So, for example, some library. And in order to do that, we can simply type in here import and then the name off the module. So, for example, platform right, And then we'll import the platform module ensue are application into this file. All right. And then what we can do is, for example, print the platform Dodd. And as you can see, there is a lot, a lot of stuff that we can do with this, right? So we can, for example, for Indy system. And if I run this application, it says 24. But then it says the system that I'm currently working on it says that I'm on Windows, right? And as you can see, there are a lot of things that you can do. So that's that's quite simple, right, that it can be useful to figure out what the user uses as a operating system. That's quite useful in some cases. And you can also figure out the version off the operating system. And, yeah, there are a lot of more stuff. So if you just I d dot in here, you can go and find out whatever you want to do, right? You can figure out the bison built, for example, So what? Bison build it, the uses. So if I run this, as you can see, it's just these these things and yes, Oh, that's how you can use a different module or module that somebody else created and use it in your application. All right, so you simply import the name of the module, and then you can use it as a library, all right? And yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask, and I will see you next time 40. Final40 Modules 2: all right. On one thing that I forget to mention is for in the previous lecture is that you can inboard only part off file. And another thing is that you can import also a variables from the file. So let's say that in the functions that bison, I don't have any variables defined in here, right? But I can do so I can define a very ever called X, and I can set it to, let's say, 1000. All right, so then I can use this variable in the modules that typhon and, for example, like this. So if instead of defector or four, I simply say x. And if I run this, it says 1000 so I will just come and this line out and yeah, so it's is 1000 so I can access even the very evals in the file that I'm importing. All right. Another thing that you can do is import only barred off the file that you are important, right? So, for example, in this functions that python you have a free methods, rights free functions. So this one than this one and then this one, right? But these two doesn't do pretty much anything. Right? So we will use only the factorial function that is in here. So we want to import only this factorial functions. We don't want to import these two. All right, So how do we do that? Well, in the modules, that python, we simply type this. So I will just get rid off this line and type in here this line. So from from which file we are important. So from the Functions file, we would like to import the factorial function so factorial like this, and then we can call the factorial function so factorial and we can call it or four, for example. So if I run this, as you can see, it's is 24. Why is that? Well, we just imported this functions from dysfunctions file. We imported only the factorial functions. All right, so only this one only this this part of the code, and then we simply used it. All right. And another thing that you may want to do is, for example, I have been here x. And then you can also use the exo brand, the X, the value off X variable. And if I run this As you can see, it's a 24. So that's the factory or result and then 1000. So that's the value of X bad. If I, for example, try to invoke one of the function that does nothing. So, for example, my function. All right, so if I tried to I called you my function in here. I will get an error. So if I run this as you can see, my function is not defined. Why is that? Because we import it from the functions fire only the factorial and the X. All right. And there. That is very much it for this lecture. If you have any questions, feel free to ask and I will see you next time. 41. Final46 PIP: All right, let's talk about a biting package manager. So in order to find out whether you have the package manager installed on your computer, you simply create a new file. Or you can use an existing file, run it in terminal and inside here. You simply ask for the version off your bison package management. All right. So simply side this version like this and hit, enter. And as you can see it right away, pretty much tell me that I'm on the 18. That one version. You may have a new around, but it doesn't matter it way if it world something like that. Your you have the package installed. If it world something like B i p, it's unrecognized command. You probably need to install it. So right now, you can use the Beckett manager to basically install some packages into your project. So in order to do that is simple type in here the command and sell, and then the name of the Beckett. So, for example, has used a chemical case. So that's quite often the package death is used to describe how the back and Wenger works. So then hit, enter and it should install the camera case into your computer, right? So, as you can see, it's is downloading the file than in selling. Right. And everything works successful insult. So then what he can do is imported into your project. So import the cattle case. So Kemah case. And as you can see, it automatically suggested me that I probably want to include the camera case, and right now I can use They're every method that issues that is defined in the cattle case . So, for example, I can create a new variable. And in here I can put camera case dot and then create a new object, Hammel case like this. Cool, right? And then what I can do is, for example, print the camera case. Dar. And as you can see, there are a few methods This this one, this hump is the most important one. And as you can see, we passing their devalue that we want to hump. So for example Ah, I don't know. Whatever. And if I run this as you can see, it's capitalized the the first letters, right? But yeah, that this is just the d camera case pick it is not so useful but it is great. Example off how we can use the package manager to install some package into your computer and then used the package and in your project, right in your applications. So, yeah, that's pretty much it. You can go to the page that I linked as a resource to this lecture to figure out all the cool packages that you can use in your projects. All right, so, yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask and al soon excited. 42. Final41 Class, Atributes, Instances: All right. So how to create a glass in bath in? Well, it's quite easy, actually. Simply type glass and then the name of your class. So it can be, for example, my first glass and then come and inside here, he type all the attributes and all the methods of your class. So, for example, I can have attributes like, at no X, which will be in danger, And it can be ik off to five as a default value will be five. All right, then I can have, like, a name or whatever, and the four value will be just empty strings or right. And yes. So let me just right now, let me just create a new instance off this glass. So if I want to create a new instance, I simply create a variable. I somehow call it. So, for example, instance one and I was said it's a new instance off the my first class. And when I want to create a object that is the off this class, I simply typing here my first gas and then parentheses. All right, so the name of the class and parentheses and this will basically create a new object that have all the attributes and all the methods that this glass have. All right. And yet I can also create other instance. So instance, number two. So this will be the same object, right? But it will be the second object. So if I Then, for example, changed the value off eggs off the instance Run. So instance one the that X. All right, So when I want to access some attribute, I tied the dot and then the name of the attribute all right? And as you can see, the computer automatically suggests me that I'm probably looking either for name or ex. Right. So I want to change, for example, the extra 10 and then let me just brings out the value off X off the instance one and then let me just print out the value off X of the instance, too. So if I run this right now, well, the instance to be changed Will the second brain will say 10 or it will say five. What do you think? Well, it will say five. Why is that? Well, we only changed the value off the instance. One off this object. All right? and this object is completely different. Object, right? It doesn't. He doesn't care whether we changed the value off some random object, right? He only cares when we changed his value. All right, so it's the same as with the glass of water, right? If I'm drinking for mine, glass of water, your glass of water will not be affected, all right? 43. Final42 Self, Methods: All right. So let me just right now, show you what the self is and how you can create a method. So, yeah, let me just get rid of this stuff and let's start creating something useful. So will create a class called point. And this will represent a geometrical point. Right? So, for example, it will have the x coordinate, and it said it zero from the beginning and the y coordinate and will also be zero. And let's also define a method. So, for example, define And in here what it can be something like move point so we can move point to some coordinates, all right? And what arguments we want. Well, we want the new coordinates, right. So the x and y that we also need the object that we want to change. So the object that we want to change its himself All right, So we always put in yourself, and then we type in there the arguments. So the ex and why? So I can, for example, college in New X and the new wise so that do you know what I'm talking about when I say new X and not only X all right? Yeah, but never mind. And then let's say what we will do. Well, we will set the X coordinate off the object that we call dysfunction on two D X. All right, and sorry to the new X computer automatically fixed me, but never mind. So and then we all self set the self doubt. Why do the new I right? So we will basically change the coordinates off deep point. All right, so yeah. Right now, let's let me just define a new class off. Sorry. A new instance off a point. So, for example, let me say just a origin, and this will be a instance off point, and yeah, we want the origin to be at zero and zero. Right? So then we can create a new instance girl, for example. I know my point. And this will be equal to once again. Instance off point. So this will be the type off. This is a class point, all right? And then we can call the method over the my point. So as you can see, it accepts free arguments. Bad. How do we call a method? Well, we do it a bit differently. So in here retired my point, Den Dodd. And then we have the move point method. And inside year we type the new X, and he knew I. So, for example, 10 and five. So, yeah, I get that. This might be a bit weird, because when we talked about functions, we have, like, free arguments, right? And the 1st 1 should always be first in these parentheses, right in the function CO. Well, it is a bit different with objects because you call a method over some object. Always you. The first argument is basically this thing. All right, So this object that you are calling the method over so this object is basically equal to the self variable. And then we are setting the X and the Y property, the attribute off, this my point instance, and we're sending it to the new X and new I, Which are these two values? All right, So if I, for example, to find another method called print point, I can simply do that and I will only accept these self and then I would like to friend. I would like to bring for example, the X is equal yet whatever, and then I can turn the self into string So the I chord in that right so self Dodd or sorry , the X coordinate, right? So I print X is equal to the value off the X attribute off the self object. All right. And then I will, for example, print or I can print it on the next line. Maybe it will be better, so I'll print on the next line d Why is why is equal to the y? Coordinate writes String the self doubt why like this And there's so let me just right now pretty points So my point Sorry my point. And then that and friends point There should be something like that, Friend point, as you can see in here. So if I run this I get an error because I forget on the come in here. So if I run this again, I get X is equal to 10 and why is equal to five? All right, so basically this method changed the x and Y property off the my point object. And if I once again Randi origin So if I, for example, try to bring the origin so print object, bring point story and I run the program. It says X is equal to zero. Why is equal to zero? Why is that? Well, because we only change the values, the attributes of the my point. All right, so these self is extremely important. And basically, these self is just a reference to the current object that we are calling the method on. All right, So we can then access the attributes off the object, right? Wound itself, D ward. And yes. So because in here we have the my point name, and then we have the origin name, so it's kinda hard. How can this method know how this object is called right? He cannot. So we just basically said it to this self. All right? And did That is pretty much it for this lecture. If you have any questions, feel free to ask, and I will see you next time. 44. Final43 Constructor, Deleting: all right. In this lecture, we will talk about something called constructor and what that means. Well, basically, constructor is some function or some method that gets to be called each time we create a new instance off that particular class, right? So, for example, each time we type in here d point, the the constructor will be called. And in order to define the constructor, we can do it like this. So, for example, in here I can say I've defined. And then I would like to create the constructor. So it's happen here. These two signs. All right. And then I stopped in here, the in it and once again, these two same sites and then we take some pere meters. So, for example, we can take the self the object, and then we can take the No, the X coordinate and the you I couldn't it right. And yeah, and then we can define what we want to do with them so we can create a new object and we will set the X property. So, for example, in here we will type in here something like a new new X has new I all right? Just to be sure, and in here will be just the X and this will be equal to New X. And then we will also said the U Why? And that will be equal to the new what right and so like this and what that means. Well, basically, when we created point in here, we specify what should be the values of the X and y. So, for example, zero and zero. Right? And in here we can do, like add No. Also, for example, five and two. All right, so if I run this as you can see, it's still in here. We changed the values, right? We changed the values off the X and Y properties, but in year, it's zero and zero. And if I, for example, change it to one end one Oh, sorry. One and one and run this program. It should say one and one. And the dust. All right, so in here we can basically define the default values, the initial values off the attributes off that particular object. All right, off that particular instance off this glass and yes, so we can also set in here d default. Eso saying way s with the previous function. And then we can, for example, get rid off all of this stuff. And when we call this, it will still work. But there will be the default values zero and zero. Right? And if I, for example, change it to too and two, there will be two and two. So it works exactly the same way as with functions, right, Onda. And we don't get an error when we don't best any arguments. So yeah, this is basically the constructor and how you can define a object. And another thing that I want to show you in this lecture is how you can delete a properties of particular object. So, for example, in here, let's say that I met and I want to delete the X property off the origin. All right, so I can simply type in here. Delete arjun dot sorry dot Exe And this will basically delete the origin that X property. So then when I, for example, wants to friends the origin that X, I will get an error. So if I run this as you can see, we get an error point object. Have no attribute, X, Why is that Well, we just deleted it. But if I, for example, type in here the my point, let's see what happens. And if I run this, as you can see, it just worked. The X is still 10. All right, So, yeah, that's how you can also delete the the properties. And you can also find out the type off the object by simply typing inner in here the type, and then you pass the object. So, for example, the origin and let's see what type of the object is. As you can see, it's this class that made that point. So Maine is basically this file, and point is the name off this class. All right, so it basically tells us. Okay, you have there eight point. So, yeah, that is very much it for this lecture. If you have any questions, feel free to ask, and I'll see you next time 45. Final44 Inheritance: All right. So in this lecture, I will talk about the inheritance, and we'll go through the basis for fruity example from the previous lecture. All right, so let's create a glass called Animal. So animal. And in here we will define the constructor for it. So in its and then we will past itself the name of the animal and, for example, the age of the animal. All right. And then we said, basically the values off these attributes. So the name attribute off the animal will have the name value that we pass in here. All right. You can always change the name off this, too, so that it's for example, And no, a name. Whatever right about this will work. This will work dough, all right. And then we can said these self doubt H Sudi h property to the h Attribute that we pass. All right, so the H property will be equal to the h attribute that we pass. All right, Cool. And they're so that's basically the constructor. Then we can define a function like make sound all right. And this one will take only the self. And it will basically, for example, print just know. Hello. My name name is and then the name of the animal. So self, that's name. And so that can be, for example, the animal class. And then we want to create, for example, I know a dark class and the duck class will inherit from the animal class. All right, so we'll create a class called Doc. And how do we create the inheritance while simply indie parentheses behind the class, we type the class that we want to inherit from so animal. All right, so that means this dog class inherits from animal. All right, And then we ready. Come. And for example, in here we can define the constructor. So in it and that every, for example, past itself, the name, the age, and what can dog half a owner, for example, So owner and yeah. Then we basically define the attributes of the dark. So dark will have the owner a tribute. But the name and the age will be attributes that he inherits from the animal class. All right, so that this may take some time to sing in, right? But the owner is the only attribute off the door class. All right? other attributes are inherit. So how do we basically Right now we would like to call the animal class right? The constructor off the animal class, Because we want to said the name and the H, Right? So how do we do that? Well, we call the super So Super, and that basically allows us to excess the the parent off this class. All right, So the method off the parent of this class and in here, we can type in here the ended function. So in it. And there we passed the itself, and then we passed the well, sir, we don't as the self the self gets passed automatically, right? Because we we simply typing here the super right. So he knows that I'm calling it from this dark instance. And so we passed the name and the H right at as a cane. Asi can notice when it's Abdi arguments in here, it automatically underlines the argument that you are currently typing. All right, so name N h. So this will take care of the construction of the animal object and then we can easily set the owner attributes off the dark so self that sort yourself dot owner like this and we will set it to the owner that we best in here. All right. And then we can, for example, defined a function in here. So, for example, something like who iss your owner? There's just too complicated. But whatever, Who is your owner will be the function. It will take the itself as an argument, all right. And so the instance of a object. And let's say it will brand. For example, my owner is and then the name of the owner. So owner, so self, the owner and self, that owner. And so let's let me just right now create these the instances off the dog class. So, for example, in here I will define then So that will be the name of our dog. And we will create a new instance off the dock last so dark, then parentheses. And yes, so right now what we need to pass. Well, we need to best the name, the H and the owner. So the name of our dog will be ban. The age will be, for example, I know 10 So 10 years old, the owner will be, for example, yuk All right, and S O that will create our new Ben object. All right, so new instance Off, Doc class. And when I, for example, once you print a I know some attribute off the animal class. So, for example, the name or the then so then that name. I can simply do that. And if I run this program, as you can see, it brings Ben. So we basically from the dark object, we access the name that is defined. So the attributes off the animal class. So as you can see it, it really basically takes all the attributes from the animal class and also all the methods . So right now I can, for example, do a ben dot makes sound, which is a method, but it is from the animal class, right? So when I run this, it will basically bring the hello. My name is Ben. All right, so basically, this line, even though I am calling this over a dark instance. All right, so and create a dark instance and it will basically call a method from the inherit class. All right. And yeah, I can obviously simply call the ban. Who is your owner, right. So who is your owner, and I can once again print it. So if I run this as you can see Yeah, then not I would like to write Ben. So sorry about it. And if I run this again, it says my owners, Luke, which is correct. So yeah, and nothing that I would like to show you is, For example, if I defined the who is your owner method inside the animal, for example. I know. Why would I do, dad, But yeah, By not in here, I conserve something like just error. And if I run this right now, as you can see, it brings my owner is Luke. Why is that? Well, we we are calling this this Who is your owner? Over a dark object. So this method is the one who executes the order. Right? So we will bring this line that even though the animal have also the same methods So same name, right? Who is your owner? And same attributes, right? Everything is the same. But this method is the one who gets to call. All right, so that's a important thing to note the idea that it's very much it for this lecture. If you have any questions, feel free to ask End. I'll see you next time 46. Final45 Protection: All right, so let's talk about the privacy off attributes and methods. So why do we need that? Well, sometimes we would like to define an attribute off, for example, a point. But we don't want the user off this module to be able to change the attribute, right. So in order to do that, we can define a private and protect it attributes, and same goes for methods, right? So, for example, only we want a method. And we want the method to be able to be called on Lee from the file where the classes defined, right? So we make it private. So did the user. Cannot call it right that Yeah, let me just create a new protected variable. So in order to do that, you simply type one underscore and end the names. So, for example, a color. So this is a protected attributes, and I will just set it to, let's say rat and yes, So I basically if I run the file, everything works. So if I I just created a color that is assigned to every point and should not be changed by a user. All right, so if you use the point glass in some other file. So if in four d point class and then you create a new point, you can, for example, then print it. So if I run this as you can see, there's the born But what? You can also do its access de private, the protected property. So if I have brains de my point So my point Dodd dash color. And if I run this as you can see, it works so I can access the property that can I change it? So if I do something like my point, dad, underscore color and I will set it. Sue, for example Blue. Can I change it? Can I do that? As a matter of fact, I can. And why is that? Well, in pretty much every programming language, if you create a protected variable protected attribute the user it's not able to call it from other file. Right. So if you in four d class and then create new object, you should not be able to change the private property and yeah, but in python they took a bit different approach. They want to be the bonding language to be as strong as possible. So that you can do pretty much anything but yes. Oh, they allow it. But that's a a bit of a problem. You should never do this if a if you are using a module, that somebody else road and they make a private property so protected property Sorry, By where this one underscore you, you don't want to change the value. You may only want to excess it at rare cases, but usually when somebody creates these these protective properties, they also define something called getter and setter. So let me just to find them in here. So get her is basically something that gets the value off the attributes of the protected attributes. So for example, in here it could be get color. And then if, as the self and then it will just simply return the value of the self dot dash color, right, so that's that's it. And the centre means basically that you want to set the protected variable so set color and in here you passing the the self and the new color, right? So and then you simply just set the self dad on the score color and to to be equal to the new color. All right, so that's just a center and get her, all right. And yet all they do is basically said the value of the protected attribute and get returned the value of a protected attributes. So each time you import a module that have a protected attributes, you shoot excessive Onley y de getter and setter. All right. And yes. So another thing that you can do is change it to private. So how do you define a private? You do it while to underscore. So like this, right? So there are two of them. Same thing as with the in it, right? And right now, if I, for example, I will change these two too. So if I change this one and this one and randy file, I get an error. All right. I forget come, like right here. So if I run this again yet everything works. So right now, the color is private, so that means we are not able to excess it. And in order to demonstrate, this simply can go to the other file where you import declasse and then asked for D color. So as I'm doing right here. So if I run this program. As you can see, we get an error. So first of all, we created point. That works just fine. We print the point that also works. But in here we get an error because the object have no attributes. Digest color. Why is that? Well, in here, the color is private. All right, so we are not able to see it in the file when we in Ford, the the class. All right. And yeah, just to be absolutely clear, you are able to see it. Why are one trick? But I won't even show you the trick because you should never use this. You should never excess a private, very private attribute or private method. Who? I had the trick. All right. You should never do that. So I won't even show you the trick. And that's pretty much it for this lecture. If you have any questions, feel free to ask, and I'll soon, Next time 47. Final47 Iterators: All right, So let's talk about its Raiders. And it Trader is an object that contains accountable number off. That is so. And it trader is an object that can be traded upon. Right, So you can you can go fruity values. So, for example, a list. So, for example, if I define a new list so my less like this and set it to, for example, that he's like 12 free for five, I can it straight through this list. So, for example, I can create a very ever called my It's Reiter. And I can create a traitor over this list using the IT sir function, and we passing there the list. So my list and then what we can do is, for example, trained the right don't want apprentices in here. But what we can print is, for example, the next off that it's Raiders. So my traitor. All right, so if I run this if I run this, you should be able to see the D number from from my list. All right. So as you can see, there is this so right, the first number. And as I it's right throughout the the list there should be two free four and five. All right, So if I run this once, you free for five. Good. But what happens if I try to hit rate from to the six number that is not in there? So if I run this as you can see, we get the stop alteration. All right, so that's basically this the error. All right. So yeah, this is basically not so useful. You can do it. Where? A group. Right. You Can it rate throughout the host whole list where a loop. And yet another thing that you can do is, for example, change this to a string. So, yeah, I didn't mean to do that, but like this, for example, So if I run this well, it's rate throughout the characters off these drink. All right? So you can do it over a list over dictionary, over, set over Toppo and over strengths, right Body. Yeah, that's not so much useful, but a thing that could be used for a straight a class where you can define, for example, a your numbers list. Right? So some sequence of numbers. So for example, class and he will be my sequence Well, let's just make it sure short and in here you're creating method so well defined. The method called It's Rebel. So it's error right and this one will take only these self object and what it will do. Well, let's say that it will said the current number off the objects so self that current to, for example, zero. And then we will, for example, each sand reiterate we will increase it by five. So yeah, that then another important thing is that the it's aeration method must always return the it's Reiter. So we will just returned these self all right, And yes, so this might be a bit weird bar you will get used to it. And another method that you need is the next right. So next, right, as you can notice, we in here we call the Itaru Asia it trader, and in here we call the next right. So these are the two methods that we need to define. And once again, it will take only these self as an argument and what you will do. Well, we're turned the value. So, for example, we were turned the grand value off south and then what we can do. Well, we can incrementally by five. So, for example, we can put these self dark current well, or we can first, incremental by five. So we'll do, plus equal five. And then we will basically return it as he numbers. So return the self that current. All right. So if I run this well, if I create a new object, So, for example, s whatever, and it will be my the object. It will be just an instance off the my sequence number. All right. And then we create a its radar over this. So my editor will be equal to its radar over the S object or red. And then what you can do is print it out. So print the next off the my it's her object. All right, So if I run this as you can see, it's his five. And if I do it again and again like this, if I run this, it says 5 10 15 20 All right, So we each time we asked for the next number we incriminated by five. We can do also by one. It's that's up to you. Whatever you want, right? So 12345 And you may notice that this is basically how we can define the reach, Arrange function If you remember from the a previous lecture far, far previous when we talked about cycles for loops and stuff like that we have the arrange function. So this is basically how you can define a wretch function, simple range function, and another thing that you can do is iterated only. So, for example, the current ISS some value. So, for example, you can iterated or you can be You can ask for the next only if the current is smaller than 10 for example. So if self that current is smaller than sen, you will return d basically the next next number ideal implemented by one and return it. But if it is not, you can return a exception, right? So you can raise the exception. Remember as when we talked about the try and accept. And remember, when we get the error when we try to go and it rate throughout the list to a character that is not in here, well, we will do exactly the same here, so we will define a exception. And how do you do that, you simply type in here race and then the name of the exception. So in here it's Stop it, Thracian. All right, so does the exception. That's all. So if I run this, it should work just fine. Since I'm bringing printing only 1234 But yeah, if I change it, for example, to free, so we will get an error. So if I run this as you can see you once you free works is fine. But then we get the stop it rations error. All right. And yeah, And another thing that you can do, which is a bit more useful is loof rowdy cycle. So four X, that is in the my traitor like this. I can, for example, print the X. All right, so if I run this as he can see, it prints only 12 free, and then it automatically stuffs when the stop alteration is race. Right? So if I, for example, change this to 10 it will step at 10. All right? As you can see, so that is quite cool, right? And if so, that's pretty much it for this lecture. If you have any questions, feel free to ask End else. You next time 48. Final48 NumberOfOccurrences: All right, So let's say that we have a list and we would like to figure out how many. For example, tents are in duelists. So let's write a function that does that. So simply defined a function, for example, number off and it will basically, except the less so, for example, the best list and well, or simply just list. And then it will also accept the element. So, like this. So the number off occurrences off this element in the list all right. And how do we figure out how many times is the element in the list? Well, we will simply to keep a variable. So that will be something like, how many or just a currencies? All right, so I'll just simply coffee pays this one, and we will set it to zero from the beginning because we don't know how many times the element is in the list yet. But then the idea is that we will go throughout his whole list element by element, and we will compare each elements to this element attribute, all right, And if they are equal, we will increment this a currencies all right. And if they are not we'll just continue with the next one. And when we reach the end in this variable, we will have the final result. All right, so let's do that. So, for each e as a element in the list we want to do, what do you want to do? Well, we would like to check whether e is equal to the element, right? And if it ISS, we would like to increment the A currencies. All right, so we can do it like like like this. So plus equal one right, we can do it like this. So is equal to currencies plus one. Yeah, that's up to you can displace equal. Or you can use this notation that's up to you. But if it is not what we want to do Well, we would like to just continue. So we do nothing, right. And when we reach and we would like to return the number off a currencies and as I said before, we store it in this variable, right? So if I now try to run this program and, for example, friend, the number off a currency's all the test list. So sorry, Test list. And in here the element will be, for example, 10. So there should be free. Right free should be the result. And as you can see, there's free. So let's try it out for five. So if I run this, it's a stew, and there are two of them. All right, so that's quite cool. And let's also try it for one. And there should be only one yet. So yeah, that works. And let's also tried, for example, for zero. And there should be zero all right, because there is none off the zeros in this list. So yeah, that is pretty cool. That's how you can implement the number off currencies and the list. So if you have any questions, feel free to ask, and I'll see you next time. 49. Final49 Reverse String: All right, So let's implement the river string algorithm. So, as you probably know, you can use the pre defined algorithm, but that's not the point. And by implementing this algorithm, you should kind of learn how to create your own algorithms. All right, so when you then come to a real problem, you should be able to solve it. All right. So, yeah, the idea is that we have a strength, for example, ABC, and we will change it to C B. A. All right, so how do you algorithm should work? Well, as you can see, we have the ABC. So how about we go from left to right? So ABC and we we take a character. All right, so a And then we put it at the beginning of a string that we will create, right, So we will create some local variable. And in there we will kind of keep the careened result. All right, so we'll always add the string to the beginning off the variable. So, for example, the variable will start as an empty string. So we will, at a then we will go through the next character. All right, So, Daryl, BB So we take B and we added a d beginning, as I said before. So right now there is a So we at a B two d beginning, all right. And then we get to the last character and get to see all right, and then we runs again, added to the beginning. And once we go through all of the characters, we returned this as a result. All right, so that's quite simple idea. So let's implement it. So we will simply define a new method called reverse. And yeah, it will accept a string, and we'll reverse it. So how to do that? Well, in here I will define the results, vary a book, and in the beginning it will be just an empty string. Right, So this is the result variable. All right. And then, as I said before, we will go through the characters in the string. So for each character and the string, we would like to go through it and add it to the beginning off the result. So how do you do that? Well, we can basically said the yourself variable to be equal to D. C, plus the result to whatever is in the result variable currently. All right, so yeah, that's exactly how we do that. This line might be a bit harder to figure out in the beginning, but it's not so complicated, right? You basically take the character and added to the beginning of the result. And once you go through all of the characters in here, you can simply return to yours out. So returned, the result and their that should work. So if I, for example, try to print the result off reverse and then I pass in there, for example a B c d. Whatever. So if I run this, as you can say see, it says the c B A. So yeah, reverse the string. So, for example, if I pass in there hello and run decode it says O l l e h So I guess that's right. Yeah. So, yeah, that's basically how we can define the reverse string method or by yourself. And if you have any questions, feel free to ask and I'll see you next time 50. Final50 Sum Of List: All right. So the next algorithm that we will implement escort the sum of less. I'm not sure whether that's the proper name. I just called it this way, but yeah, it basically takes the list and returns thes some off all the elements in the list. All right, so how do you do that? How do you create such now? Go to them. Well, the idea is that we will have a variable in there. We will keep to yourselves, and we will go through all of the elements, and we will basically ad at the elements to the result. Variable. All right, so let's do that in here. We will define, for example, a some off list, and it will take the list, right? And 40 list what we will do. Well, we will create the result very about. And from the beginning, Ribble said it. Zero. All right. And then we will go for every element. So oh, meant in the list number as sorry in the list. And what we want to do is basically add the element to the results, so results will be plus equal the element, so yeah, that's pretty much it And then we can simply return the result. So as you can see, it's quite simple. And and if I, for example, try it out. So if I print the result off some off list and I passing there some list So, for example, 15 and five and two, So that should be 13 and in here? Yeah, yeah, that's that's it. And if I run this, it says 30 right? Cool. So that works. And yes, so, as you can see, there is a bit of a pattern. With this problem, we always go through each of the elements. We sometimes have some variable in where we keep the results. Right? So pretty much these two algorithms are not so different. And yes, So if you have any questions, feel free to ask, and I'll see you next time. 51. Final62 Biggest in List: All right, So in this lecture, we will solve the biggest number enlist problem. So the task is quite simple. You simply get a list and you want to return the biggest number from it. So how would we do that? Well, I will simply define this method. This will be or function. This will be just at no biggest. And it will accept the list. And for the rest, what we want to do. While first of all, we would like to define the biggest yet, right? So the biggest Well, just the biggest number, all right. And this will be what it will be. Well, we need to set it to the first number from list. Right. So list on in the egg zero. All right. And then we will go, for example, while i All right, So I will be one. So we will start at index one, and we will compare it to all the elements behind. And if we find element that is greater than whatever it's stored in our biggest, we simply changed it. All right. So you will change the value off the biggest, and yeah, then continue once again with elements behind And when we reach the end, we have the biggest number in the biggest variable. So inside here, real simple time, the wild cycle. And we'll cycle while I a smaller than the length off the list. So like this. And yet And then we will Basically, as I said, we will check whether the element on index I All right. So, for example, right now, it will be on index one is greater than whatever is stored in the biggest variable. All right, so weather d or, in other words, whether the biggest is smaller than the list on index I. And if it ISS if it is, we want to set the biggest to the list to the number behind it. Right. So, to the list on index I. Why? Because the list on Index I is greater than the biggest set. And yeah, and And we need the biggest number, right? So it should make sense. And then after this condition, we need to increment I. So I plus equal one. And after this wild cycle, we can simply return the biggest because that's the biggest number. So let me just try this out. So inside here I oldest Brent. So print the home. I got print and inside here we will bring the result off. Biggest off. I know. Let's say 158 it's and one to whatever. Last number will be six. So this should be, like 10 right? So if I run this, as you can see there, Stan and yes, so it would work for all the numbers. If I change, just want to 11. It will bring to 11. All right? It works. So yeah, that's very much it for this lecture. 52. Final63 Number of words in String: all right. In this lecture, we will talk about the number of words and string problems. So the idea is that we get a string and we need to compute how many words are in the strength. So in other words, we need to compute. How many spaces are there? All right, so But as you can see, there are four spaces, right? So one to free. Sorry. Free and four bod. There was five words. All right, so yeah, so let's define the function so defined the for example, number off words, and it will accept some string. So, for example, just a input will call it and put and what we need to do well, inside here we will define a variable called count, and we'll set it by default to one. All right, And then the idea is that we will simply count the spaces in our strength. All right, so how do we do that? Well, we can just loop throughout the whole string. And if a character is equal to just a a space, we simply add it right. We can simply just add one to the count, and then we will have in the count Variable will have the number off words. So, yes. So for every character in the input, what we want to do Well, we want to go through it and check whether the character iss equal to space. All right, if it is, we can basically incremental accounts account will be plus equal +10 sorry. Plus equal one. And if it is not, we can simply move on. Right, Because we are going through some word and and then in the end, we are done and we can simply return. He count. So like this. And if I, for example, right now, bring to this, so try it out. So, friend, number off words and inside here I will best something like Well, maybe I will just bans this string to say sometime and s So if I run this as you can see it , Prince five. So that's quite cool. And if I delete for example one word it will brained for So yeah, that's cool. But the problem is that if I bass, for example, just an empty string, it will bring one, but but empty string doesn't have any words, right? So that's just wrong. So what we need to do. Well, first of all, we need to check, so I'll just check if the well, first of all, the the length of input is equal to zero. We want to just return zero, right, because there is no character. So if the length off the input, so like, this is equal to zero, so I can do it just like this Equal zero, I want to return zero. So I just want to return zero like this, and yeah, and another thing that can happen is that somehow the string, for example, ends with a space. So, like this, right? So even though there are actually, like two words, so desu likes the computer returns free. All right, so we also need to check whether the string ends with the with the space. So we will do that down here after this cycle. All right, well, just basically ask if the input if the input on index off length off the inputs. So the last element minus one, So this will basically takes us to the last element. All right, so this is the index off the last character, all right? Because the length of the input points, right? Right behind the strings. So minus one basically takes us to the last character. And we check whether it is a space and a Ferris. We can simply decree Mandy counts. Account will be minus equal. Wanna all right? And yes. So if I run this right now, it should bring two and a dust. All right. And there So But if I, for example, get rid of the space, it still says to, So that's correct. And eso that is pretty much it for this lecture. If you have any questions, feel free to ask End also next time. 53. Final64 Is Prefix: all right. And this lecture, we will take a look at the esprit fix problem. So basically, we will define a function that takes two strengths. 1st 1 is just a string, and 2nd 1 is the prefix, all right. And we will check whether this string is a D beginning off the 1st 1 All right, so as against the in this case, this is true. And in this case, it is false because it starts with a B, not BC, All right, so let's the finding function so defined, the ISS prefix. Ah, and it will take just two strength. So, for example, just an input and then prefix And what do you want to do? Well, first of all, we would like to check whether the length of the prefix is smaller than the input. Right. So in other words, we can check whether the length off the input is smaller. Then the prefix right? So if the length of the input is smaller than the prefix, the prefix cannot be they the start of the length of a sorry of the input, right? That doesn't make sense. So the length of a prefix. So then we just know that we can just return false because that's just false. The prefix cannot be at the start of a input. If it is longer, right, That just doesn't make sense. And yet But if if it is equal or smaller, we can simply luv fruity prefix and check Verity element on index I off the prefix is equal to the element on index I from the input. So yeah, in order to do that well defined eye and we will start at zero and then we will go while I is smaller than the range. Well, yeah, we can do it just why A for loop for a while loop. But it pretty much doesn't matter. You can do it. Wherefore roop with the range function. But if you do it while via loop, we can simply do it while I a smaller Dendy length off the prefix right? Because that's all we care about, right? The other other characters in the input are just We don't care how they look like So then what do you want to do? Is check where a d element whether it be character on Indy prefix on index I it is equal to the element in the input on index I right, If it is, we just continue with the next character. But if it is not, we need to return false. So how do we do not equal? Well, we simply change this to this. So the explanation mark means not equal. So if it is not equal, we return false. Right? So you return falls Because there is no point in comparing all the other characters because it is already know a free fixed. Right. So yeah, Cool. Then what do you need to do whenever we need to increment I so I will be plus equal one. And when we increment, I re basically move in the Indies race off characters and their when we reach the end. And we didn't return True. That means all of the characters are equal, right? So a is equal to a B is equal to be. And we reached the end. So we return true. All right, so inside here you can simply type return true And yes. So let's let's just this so brand. And inside here I'll just bask these two and this is bring true. And then I will pass these two. And that should print false. So inside here once again print. And let's try this out. And yeah, all right. I had forgotten they function girl. So it's prefixed, obviously. And then we best desu All right, so that's a bit embarrassing that whatever I will not I will not cut it out. I I promise. And inside he will also do the esprit fix. And if I renders again, it works. Right? So the 1st 1 returns true and the 2nd 1 returns falls all right. And eso that's about it. If you have any questions, feel free to ask and I'll see you next time. 54. Final65 Is sorted: all right. So in his lecture, we will implement the algorithm that is solving the problem off finding out whether a list assorted So, for example, this 1st 1 is not sorted because nine is obviously a smaller than 11 for example. But this one is sorted. So it goes from the smallest to the biggest element, right? And as soon as they find the function that will check that so it's sorted and it will accept the list, right? And then what we going to do? Well, how do we know that our a assorted well, if every if we take a look at every two numbers or two elements from the from the list If the left run is always smaller, dandy right, one smaller or equal to the red one de array assorted right. But if at least once the left once so that means for example, 11 is small is greater. Sorry, then the ride one. So, for example, nine we, the or a is not sorted, right? So basically we will check for this so we will check whether the left one is always smaller or equal to the right one. And if it is not, We will return falls. So we will go through the You're A So I will just define a new index co and our snack. Assign it zero and we'll move while I is smaller than the length off the US right And what we want to do. Well, we would like to check whether the element on index I IHS smaller or equal to the element on index I plus one. Or in other words, we would like to check whether the element on index I is greater than the element on index I plus one. Because if it is, we know that the array is not sorted and weekend just return false. So, yeah, let's do that. So if the list on index I is actually greater than the less on index I plus one. So the element behind we returned false, right? So return like this. False? Yeah. And other words that I may forget to mention is that you have to type the f capitalized. All right, so if you type in here falls like this, you will get an error. All right. You need to type force. And yet, so if back to my point if the left one is greater Dendy Right One we return false, right? But if they are not, we can simply move on. Right, So we will simply just increment I So I plus equals one and move on to the next number. So then when we when we reached the end weekend simply return True because we know that this condition is true s aura is false for all the numbers, all right. And yet another thing that you may want to notice is that will his work, In my opinion, it will not bad. Why? So you may want to pause the video and try to think about it. Why? This will not work that I'm about to tell you. So pause it right now and yes. So the problem is in the length of the list. So we are checking whether I is smaller than the length of the list. But then we reach for the I pass one. So what happens? Well, for example, the length off this list IHS free, right? So what happens when I s equal to two? Well, we are pointing at D nine, right? So I is equal to two. This wild condition is true. So we continue with these lines, so I as too. So we check 40 weather d nine a smaller Dendy I plus one so free. And there is no element on index free in here. Right? So we will get an error. So what we need to do while we need to check to the second to last number So to 11. All right. And we need to skip the last because there is no other numbers to compare it to. All right, so we will simply do that by writing in here minus one. And so if I run this algorithm, So, for example, if I brained whether it's sword it in this Ray, so this list. So if I put it right here and yeah, and I also friend, other list that it's actually sorted, So yeah, that can be, like 12 inside here. And if I run this as you can see it brains yet, Prince, also these stuff. So I'll just come ended out and run this again. And it's brains false and true. And that's correct. So, yeah, if you have any questions, feel free to ask in. I'll see you next time 55. Final51 Tkinter Window and Label: All right, So, so far, we have created a applications. Right? But those were just console applications, So basically, just text application. But all the application, you probably know are some, like graphical application, right? Like some window and some buttons inside, even dough. Right. So was that all useless? Well, not at all. So all the things that we talked about was the functionality behind dose applications. As you can see, for example, right here, and the other part of the application is the graphical user interface. So gur and this basically stents 40 buttons and the things that you see right for 40 windows. So basically everything every layout in a window as a graphical user interface of some program and all the if condition and cycles and stuff like that, they are on the background, right? They are taking care of the functionality. So right now, let me show you how you can define a new window. All right, so we will start creating a window application, so let's get into it. First of all, what we will use is a class or basically a library called TK Enter. All right, so that's probably the most used library for python graphical user interface. And there's so in order to start with that simple in here type import and in type TK enter like this. Alright, it automatically suggests to TK enter and then what do you want to do is, for example, create a new window? All right, so how do we create a new window? Well, for example, inside here, I will simply to find a window variable. And this one will be tiki inter dot and then should be t k. All right, so TK And that's basically a glass that stands for the new window. All right, so right now we constructed a new window. Instance. All right. And now what do you want to do? ISS loop through the window. Still, the application is closed by user. All right, so how do we do that? Well, we sympathize in here. Window, Dad. Main loop. All right. So, main loot. Sorry. Like this. And parentheses. So if I run this a sorry window instead of windows. So if I ran this as you can see, it shows a window. So if I simply move it inside here. As you can see, there is the window that we just created. So let me just talk you through the process. Well, inside year we tell we tell the computer that we want to create a new window. So we create a new instance of a window, and then this line basically take scare off the window being shown, because when we create a new instance off window, it basically disappears right away. All right, so this line basically takes care of the problem that the window is still being shown. All right, so that we can actually see it. And yes, so right now, let's do the fun part. So inside here, we basically take care off the creation off the window. And inside here, we basically showed you windows. So where should we put our elements when we want to add, for example, something like buttons and stuff like that into our application? Where should we put them? Well, exactly in between those two. So on the line for So for example, let me just say that I want to create a new element, and this one should be label. All right. So labels are produced simple. So we simply create a new variable called for example, label. Hello. And we will create a new instance off the TK Enter dot label. All right. And then in parentheses, we simply pass the master. So what is the master? While master basically stands for the element in which we won't deal able to be displayed? All right, so where we want deal able to be in spite? Well, we wanted to be displayed in the window, right? So we simply passing near the window. Sorry window instead of windows. And yeah. Then what we can do is define all the property. So, for example, the text which is the most important property off a label, and we can set it to, for example, hello world like this. And yeah, so right now we have created a new element. All right, so we created a new label that will be shown, indeed window that we just created on this line. And then what we need to do it's actually showed the label because right now we just created it. Alright. We prepared everything, and but we still didn't show it, actually. So how do you show the label? Well, it's quite simple, is simply type in here label. Hello. So the name of the variable and then dot and then peck so like this and parentheses. All right. You can also define the position in the bag, but we will take care of that later on. All right? So if I run this, you should be able to see really small application. And, as you can see, it says, have a world inside. So that's great. Cool, right? We created our first application that have a window and and they're so that's pretty much it for this lecture. If you have any questions, feel free to ask end. I will see you next time. 56. Final52 Frames: All right. So in the previous lecture, we talk about the labels, right? And how we can show a window bad. What we want to do now is basically tell the computer where we want to show the elements. So let me just get right into it so we can import the TK Enter once again. But since we always if we do it like this So if you type import TK enter we always need to type in here TK enter dot something right label or something like that and that's going to pain in D s. What do you want to do is simply type in here label. Right. So So something like this. And how do we do that? Well, we can simply It's I've been here this from TK Enter. We would like to import everything, which means this star. All right, so this star basically stands for everything. And right now when we want to create a new window So for example, window Oh, sorry. Window and we can set it. Only Sudi t k All right, so TK and parentheses. All right, so we don't have to ride dtk enter right now. Cool. So right now, let me talk you through the things that we need to do. And first of all, we need to We need the window to be shown. So window Dad main little like this parentheses and then we will define few elements. So each time we want to style something, so that means basically divided the windows into some parts. So, as you can see on this editor, as you can see down here, there's one part for the council, and in here is out of Bart Ford. Easy files, right? And in here is out of Bart 40 texts, editor and stuff like that. So the application is divided into parts right into like invisible rectangles, basically, and these invisible rectangles are called frames, so frame is basically a part off the application. So part of the window where you can place other elements, but there's not actually any element, so you cannot see anything right. You don't see the frame, it's invisible. Alright, it's only 40 programming purposes. So, for example, let me define aid sue frame. So 1st 1 will be frame so f the top so f top. That will be a frame on top and then we will have a frame on Barden. All right, So defray mont up will be simply created by tapping here frame and then in parentheses. We want to pass d master. So dead will be the window, right? And yeah, so that's basically it. And the other part that we have to do when we create an element, we need to show it. All right, so we need to do the frame on top that back. All right, so that basically stands all right. I want to show the frame on top, all right? And then we will create the bottom frame, so frame bottom, and this will be also a frame. And inside year, we were once again past the window and yeah, Then we simply typing here. The frame on bottom would like to be also backed. So we also want to show it about this time we will design where we want to show it. All right, so inside here, we type something called side, and then we type in there D side where we want to show it. So we have, like, left stop, right and bottom. So we tap in the bottom like this, and it's so did well, basically is showed the bottom bottom frame on the bottom of the application. All right. And then what we can do is, for example, to find a few labels. So label one. All right, whatever. And it will simply be a new label, and it will once again be well, right now there's a difference. Instead of the previous lecture in the previous, like Cherie, display the label directly inside the window. Right? But right now, I will show you the functionality off these frames because right now we are not showing the label inside a window. But we are showing it inside a frame, right? So, for example, in the top frame, so f top. All right. And then we can to find the text so the text can be something like a I know something like Hello, whatever. It can be anything and yeah, so then let me to find other LeBeau. So that will be just label, too. And then we will have once again label free, and this label will be on the bottom. All right, so in the bottom off our application Sorry. The F bottom like this and it will say, for example, bottom. And this one will say taught. All right, so then all we need to do is basically displayed. He's all right. So same thing as before. We've seen protecting here, lay. But one dot Beck, all right? And sing goes for the label to and label free. So I'll just copy Pasted to save some time. And I have been here label to and label free. So if I run this application, we get an error because he texts should be in lower case. So, like this. And if I run this again, it works. And as you can see, if you make the application a bit bigger, right, the bottom is on the bottom and yellow and top is on the top. Right? So we basically have the two invisible rectangles. So 1st 1 is up here, and the 2nd 1 is down here, all right. And inside those rectangles, we are placing the labels, all right? And there's so right now you may wonder why they are underneath, right? Why did Why? These two labels are not next to each other, so yeah, well, that's just the default setting. You can obviously change it. And how do you change it? Well, it's quite simple. So simply go back to your editor. And when we are displaying the items, what we want to do, well, we would like to display them, but left right on the left side and, for example, on the right side. So let me just show you how dead works. So inside here, retyped side and let's type in here left. And then inside here, let's type also side and let's try right so that you can see how that actually looks. So if I run this as you can see, those labels are basically next to each other. Right? So the labour one that says hello is on left and the label to That's a stop. It's on. Right? All right. So yeah, that's great. Cool, right? 57. Final53 Button: all right. So in this lecture, we will talk about probably the most important competent, which is a button in every application. You have buttons in some sword, right? In some way. So it is important to know how to create them. So in order to create a new button, I will simple create a new variable called button and I will assign it the value off a button. So new instance of a button and inside here what I will best well for now, I will only positive Indo. Otherwise you would probably want to pass the frame right? But for this teaching purposes, I'll pass Steve Endo as a master So inside, even though I will show the button and then I can define all of the cool para meters. So let me just quickly talk you through them. So 1st 1 is a border. All right, so the border off the button So if I It's by default Itsu So if I for example, I met and I will change it to 20 the border will be extremely big. All right, so that it's like that. That will be huge. And eso Dan, where recon define is for example, a background color. So simply type B. G. And he can assigned to it a value off strength and, for example, green in it. All right, so it will have a green background than comma. And each time you are defining a new para meter off the button, you simply type comma. All right. And yes, So then what? We can define where we can define the foreground. So basically the color off the text, so foreground and we can assign to it at no white. All right, so, Danna, probably the most important thing. Which is the text off the off the buttons. So what Exit will show? And for example, for now, it can say click me. All right. And yes. So it's getting quite big, so I will just hit enter. Well, I will. First of all, right, comma. And then I will hit Enter, and we'll start writing the other pair meters on the next line so it will work just fine. All right. And yes. So other thing that you may want to define is a batting. So basically betting or X so on the x coordinate. All right. And then batting on the y coordinate. So that means up and down. And yes, So it's basically a number. So I roll scientific for example 50 and depending what I will be. I know maybe, but greater so that you can see the difference, right? The button will look terrible. I I can assure you off, dad bod it will just You will see what these lines does. What the with these para meters dust to the actual button. All right, so yeah, let me just show the button. And yet another thing that I want to touch on is that for now, we used the back to display the button to display an ailment. Right? So what we can also do the peg will work just fine. But what we can also do is the place so d plays. And inside year, we can define the X and the y coordinate. So exc envy for example 50. And why I can be, for example, also 50. All right, so we'll simply defined these. We can basically defined where we want to place the elements. So if I run this as you can see, a displaced a new window which doesn't look quite good, so I will just make it a bit bigger, all right? And yes, you can see the battle looks actually horrible. It's like That's so ugly, but never mind, right? So as you can see the border, it's extremely huge, right? So the border off the button is extremely huge. So that's that's this 20. So 20 pixels, that's, like big, quite big number. And then we have the background. So as you can see it green and the foreground so as you can see the text, which is wide all right, then the text with sous creek me. All right. So you defined the click. The is already not be clicked the detective, the button and then he basically the finding batting on X coordinate. So that means from left and from right both sides at the same time, all right, And s. So that's 50. And the betting on why it's 80 right? So as against CD button is more, the height of the button is greater than the with off the button. So that's makes yet it looks terrible, right? But that's not the point. I just want to show you all kinds of cool things that you can do with the button. All right. So, yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask End. I'll see you next time. 58. Final54 Button Clicking Event: All right, so, so far, if I run, the application will get a working buff in, right, so that we can style a bit. Well, and when I say working, as you can see, when I click on that, nothing happens. Right? Only it looks weird, but nothing much happens. And there. So we want to add the functionality. You want to do something when a user clicks on the button? So how do we define what we want to do? Well, we'll define it. Why are a event? So what event means? Well, basically, when some event happens, which event is basically that user, for example, clicks on a button. We want to define a function that will be called All right. So, yeah, let's do that simply inside here. When we want to do that, we tapping here, the command so command like this. And then we type the name of the function that will handle it. So, for example, handle, click. All right, So like this. And let's define the function so defined a function gold and click like this and it will accept no arguments. And I will just simply bring a no button clicked all right, so we should be able to see it down here in D Terminal. So if I run this application right now, the application is shown. And if I click on that, as you can see it sales me button click. And each time I click, it brings out the button click again. So as you can see, that's quite cool. Right now, you cannot see it. So if I make it a bit bigger, as you can see, there are a lot of clicks. So, yeah, you can obviously go crazy with that. That that's pretty much the main point off this lecture. So if you want to define what to do when, for example, user clicks on that on the button that you created simply in the command when you could, creating the button inside the name of the function that will be called when the button is clicked all right, and then the button is called, as you can see on these examples. So, yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask ends else. You next time 59. Final55 Entry: All right. So how do we deal with inputs and bring much every application? You have a input off some sword, right? So some basically field in which you can write some, whatever, some text or something. And they're So how do we create that? Well, in order to create it, it's the creation part is quite simplest. So in here we can, for example, type the entry. So I e as the entry, and we will create a new instance of a entry object. And we will display it in our window for right, and then we can define all kinds of cool para meters. Most of them are quite similar to the power meters from before. So we can define, for example, the foreground so f g and inside here we can, for example, side green high. I don't know why I'm typing green always again. These other colors, obviously. And yes. So then we can, for example, to find the border right you can to find all kinds of stuff. So, Al, just make it for example five. And for example, let's change also D background. All right, so background. And that will be a black all right, So black and yes. So let me just display a distinct so simply e dot beck. And then so if I run the application, you should be able to see a black and put that takes a green text. And there you have it. So black input. And inside here as I'm typing it's green text. All right, so it's basically, like a metrics or something like that. Yeah. So it's exactly not like metrics, but whatever. And yet then we can accept the variable. So what we want to do now is basically take the text, the that the user rights all right, and puts it into a variable. So how do we do that? Well, first of all, we need to define a new variable called for example, inputs. So that would be what, use a road or Yeah, it's gonna be a different, for example, user road. All right. And yeah, and we will assign it to a new instance off the string. Variable object. Right. So, like this. So this is basically an object that is designed so that it can take as a input the entry that user wrote. All right, so the stuff that use a road into the entry object into the instance. And they're so right now, it's not quite simple. First of all, we need to define de the variable. Right? So right now we need to bank this user role variable to the entry object. So how do we do that? Well, simpler. Inside here we write the most used bear a meter, which is the text, very ever. So text very ever like this, and we will assign it to the user road. So user wrote like this, and they're so that basically connects the entry and the user row variable. All right, But now we still get a problem. Because even though each time that user types a character it is bind it into the user road variable so the user world variable will be changed. We still don't have any information when the user actually types something. All right, so we don't have any like command or something like that that will event us when the user starts writing. All right, so that's quite bad. So what do we do? Well, we can define a trace. So what is a trace? Well, trays basically means that we wait for some events. So, for example, we wait, Wendy, variable use road is changed, and when it has changed, we call some function. All right, So, Yella Joudeh. So in order to define the trace, you simply type in here to use a road and then dot trays. And inside there, you first of all tab demote. So that will be W as a road. And then we will define the call back. And the Quebec is a lambda expression. All right, so we type in here d lambda and it accepts free values. All right, so the 1st 1 is a name. So the name, then it except the index, and then it accepts the moat. All right? And for these free, we can do whatever we want. So we can, for example, brains. Well, yeah, we want to call the call back. So for example, friend value. All right. So that will be our function that we want to call. And yes, so let's define that. So define the print very function that accepts no arguments. And we will, for example, to sprint the value off the user road. Variable. All right, so inside here, I will simply copy paste it and then tie dot Get. So why can't I just bring to the user road variable? Well, debt is because this is a object. This is a instance of a object. And inside the instance is a variable Well is a attribute And where we have the actual text that the user road So we need this get method call to give us the actual text. Alright, that yes, right now if I run the application and if everything should work So if I move it inside here and start typing inside down here should be some text. So if I type as you can see, it brings the text as I'm writing it, right? So that's quite cool at as he can see each time I write a character, right, the exchanges. So this trace. So what is basically happening? Well, when I write a character, the trace somehow notices that I wrote something all right. And it caused Islam the expression and Islam. The expression calls this sprint value. All right, So the spring value gets to be called and the spring very basically prints the current thing that we have in the in the in the window, right? And use a road variable. So will it work? If I, for example, start the leading stuff? Well, it would all right. So as you can see it, the leads as I'm deleting as I'm clicking and then eso basically that's it. The trace might not be so clear to for now, it's It's a bit complicated topic for now. So it basically the trace allows you to define a event when something occurs. So you define a callback. So basically something like function that gets to call when something happens and you can define it over a object, which is a instance off the string there, all right. And they're so and then you also need to connect the object with the actual entry. All right, So as you can see in here and then everything works. So the getting the input is a bit complicated. I I would do it differently if I were programmed Python, but I'm not. So yeah, that's that's pretty much it for this video. If you have any questions, feel free to ask end else you next time 60. Final56 Grid: Alright, guys. So welcome to this lecture in this electric, we'll talk about the grit. So what is great? Well, you can think of a great as a imaginary table inside your window. All right, so inside your window you have something like imaginary table that have rows and that have columns, all right. And yeah, and you can place elements inside these. All right, So you can use these to basically the fine where you want to put your elements. All right, so let's say that I first of all, need to great few elements. So let's say that we will create some I know. Basic, like, luck inform. All right. So Well, we need, like, two labels for examples. So label label, I know it can be labeled user, for example, like this, and we will accept. Well, first of all, we will say that we want to accept the user name. All right, so we'll create a new labour, and inside here, well, said the master to window like this, and then we will pass in their de text fare meter, and that should be something like user name. All right, so user name and yeah, and Let's also create second label, which will be similar. Only this time it will be 40. Password. All right, So password and yeah, inside here. I will simply typed password, and all right. And then what we need to do. Well, we need the entries or I 40 40 form. So this form will not work. So I won't specify any variables. 40 entries to bind the value that these are actually world. This is just for the teaching purposes, off the grit. All right, so I'll just Grady elements. So this one will be. For example, Juan is a entry one, and we will basically just create a new entry, and we'll we'll keep everything default and just place it in Deve Indo. And then I will create a second entry so I can maybe make it like entry, password and entry user. So, like this All right. And I will be the second entry will be just a new entry that will be placed somewhere in the window. All right, so, yeah, these are just are elements. And right now what do you want to do? Is actually blaze them somewhere. So how do you do that? Well, we simply typing here the label user, for example. And we want the user name to be in the rose zero. All right. And then we own the best word to be in the euro one. All right, So underneath. So how do we do that? Well, simply inside here retyped grit. And then we passed as a para meters zero, so row will be equal to zero. All right, so this this is the roll on the tough and and then the we will also show the password. So, like this and inside here will be only the password. And we will change the row to one because we won't be password to be underneath. Right? We want the label for password to be underneath and yeah, And then what do you want to do? Is also display the great the sorry, the entries. So how do you do that? We do pretty much the same. So the entry for the user will do just grit, and then we'll play said once again in the euro zero. All right, so? So the entry for the user will be just next duty label. All right? And then we will do the same thing for the password. So entry password. And let me just run this and also change this 1 to 1. And let me just run this and see what this looks like. As you can see, it doesn't look quite good. Why is that? Well, first of all, the labels are not in here, right? As you can see, there are only the the input, all right. And the labels are underneath. All right, So what do we also need to define? Well, as I said before, there are rows and columns. All right, so by default, the columns is zero. So that means the most left one. All right. Bad. You can also said it come to one. So that means the next to the D column next to it. That's right. So you can think of it as a table. You have a imaginary table inside here, and you can place it just into some sell. All right, so let me just inside here, move these entries. Sudi column to the column one All right. And both of them will be in the column one right, because we want both of them to be placed to the right. So if I run this again, as you can see, it looks a bit better, right? So, as you can see, we have to use the name. Then we have the password. And and inside here we conserve some stuff. And yeah, so good thing that you can also do. It's, for example, aligned these two either left or right. So inside the cell, currently it is aligned to center. So I'm not sure whether you can see it. So if I, for example, changed this to only this thing and runners again, As you can see, these labels are placed in the centre. But usually they are placed to the right, right? They are usually they are aligned to. Right? So how do we change that? Well, inside here inside the grid, we can simply define it about how well we used these sticky Kerem Eser and inside he redefined the decide where we want to align it. So we have. But this one is different Inside, he retired the north, south, east and west. All right, so north means basically up south down east history, right? And west to the left, right bar eso so yeah, that's that's a bit weird because you usually want to write Stop left Baden right about the inside here you simply type the sticky alright, sticky and then the north, East, south or west. All right, so it can be either and right or stuff like that. I'll just keep it to east. And if I run this as you can see, the form looks much better, right? They are aligned Sudi right or right to the east and they're so that's very much it for this lecture. If you have any questions, feel free to ask and I'll see you next time. 61. Final57 Menu: all right. So pretty much every application Have a menu in some sword, right? So on the top, as you probably can't see it because I'm on full screen bar on the top is usually something like file at it. And yes, so some menu and each each time you, for example, click on file. There's a drop down menu, so there are several. There is like sub menu or right, and there's so very much every application Have that. So it is important to know how to create it. And I will show you how to do that in this lecture. So first of all, I will import dtk enter, so from TK enter import everything. Then I will create a new window. So that will be just a new instance off TK and I will also create demain loop so main loop and yeah, and inside here I will create the menu. So each time you want to create a menu, you simply type in here D, for example, main menu and then you assigned to it a new instance off menu. And as you can see, you have to pass the master, so that will be just the window. All right. And then what we need to do is basically tell the window dead. We have a menu, and we want to show it inside this window. All right, So how do we do that? Well, it's quite simple action inside this recent, but I've window Dodd config. So configure basically. And then what? We want to config. Well, we would like to change the menu, and we would like to set it to this variable. All right, so to the main menu. So main menu. Sorry. Like this. And yes. So that will basically take care off the connecting this menu to this window. All right, so we will have a window, and on top will be this menu. All right, So then what we want to do is at some stuff to d menu, right? So, for example, how to do that? Well, it's quite simple. So main menu Dodd. And if you type in here, add as you can see, there are a lot of a lot of things that you can do right. There is a lot of things. So for now, we would like to create a new cascade menu, so each time you click on file, we will create basically the copy off the file. So each time I click on file, there is a new drop down menu that appears and yeah, and yes, So we will do that. So in order to do that is simply type in here at Cascade. So this will basically at a new menu. And yes. So, first of all, you defined the label. So that means what do you want to say? And we want to save the file. And then you also define What do you want to show Sodi? Basically, these sub menu, all right. And yet And what? What is that? Well, that is just a instance off this menu. So we need to create a new menu. 40 drop down. So for the sub menu that is shown when you create click on the file So we'll just creates, for example, file menu and we will assign it to a menu, and the master will be the main menu. All right, so the master will not beat, even though about the main menu, because we want to show it like this should be a child off the main menu right. It makes sense, hopefully, and yeah, then we want to a san it as a menu to this main menu. So basically, right now, we edit a item to the main menu that will say file. And when you click on that, the file menu will be shown. So right now, what do you want to do? Is basically defined the file menu. So how do you do that? Well, it's great. Simple. So inside here we conserve the file menu Dodd and then add, but we will not at any any other file menu. We will simply add the command. All right. And what do you have in the file menu? Well, you have the open safe and close, right, so open. And yet and then inside here can define a function. But for now, we'll just keep it simple. Maybe we'll added later. So then we want to add the safe and close. All right? So safe and close. Sorry. And clothes and what that does. Well, basically, it adds the item into defile style menu. All right? And yes. So let me just run this thing and see how dead looks. It should already look quite good. So as you can see, there is the file, so determine you. And when I click on that, as you can see, there is the open, safe and close. So yes, sometimes in a program you may notice that there is a separator. So basically a lied between, For example, these two between these safe and the close to basically like I know at related self together. All right, so yeah, let's create delight. So in order to do that, you simply type in here the file menu and then add the separator. So, yeah, simple is that it's just a line, right? How hard can it be? So you simply create a new line that will separate the open and safe Andy close. All right, so if I run the program right now, it's quite usual. The separator, you you would have a problem finding an app without the separator, actually, so you may not even notice that, but it's almost in pretty much every app. So as you can see, there is the line between the safe and be close to basically and no separate these these different items. So cool. Now what we want to do Well, we would like to add a functionality because right now, when we click on any of these men, you it does nothing. So remember how we added functionality to the button? Well, it's exactly the same. So simply in here to have the command so command and then you tied the name of a function. So, for example, the desk function and I will also define it. So define the desk function and it will accept no arguments. And Advil just sprained some ages. Whatever. And I'll just copy paste it into all of the others. So obviously these functions would be different, right? Dysfunction would, for example, closed the window and this function were have no safety file. If you have some filing that, but just 40 teaching purposes, I will keep it simple and just bring some ages. And yes, if I click on that, as you can see, there is the H a change. And so that's quite cool, right? So let me also show you how you can add another commands. So, for example, in the main menu, you usually have something called edit, right. So let me just add it. So main menu and then we can add a and not a guest, Kate. Right, But And the labour will be, for example, at it, and the menu will be added menu. All right, so edit menu. And right now, the edit menu is not defined. So we need to create it. And we need to create it above this because we are using it right now. So inside here, I will just create the edit menu, and I everyone's again assign it to the new instance of a menu, and the master will be the main menu. Right? Because the the edit menu is a child of a main menu. It makes sense, Hopefully. And yes, so then what we can do is basically add some stuff to D added menu. So what is an edit menu? We can add command something like I know there is, like a undo. Right. So undo, undo like this. Oh, my God. I can't side undo. And then I can add something like redo and yeah, and out of so you can you want to add much more stuff. All right, value for the teaching teaching purposes. This is enough. And let me also add to the main menu. Just a simple button. So, yes, sometimes in the menu you don't want a drop down. You want only, for example, just know something like health button that will, That there's no drop down. And we're basically just open. For example, a new window are I know something like that. So simply type in here main menu and then add commend. And inside here we will for the label to be equal. Teoh help, for example. So if I run this, I get an error. So somewhere I get an typo. All right, inside here should be menu. And if I run this again, the file X quite guilt. So file everything was just fine than the edit. Okay, as you can see, undo, Redo. It does nothing because we didn't sign any command to it, right? So But the command would work also. And there's the help. So there's no drop down is just like basic item in a menu, all right? And obviously we can also assign a commence to it. Same way as before. So yeah, that's pretty much it for his lecture. If you have any questions, feel free to ask End else you next time 62. Final66 Canvas, Lines: Well, hello, guys. Send well counted his lecture and this lecture will talk about the canvas. So let's get into So can was basically means like a drawing board where you can draw a lines or shapes, right? Some rectangles or circles or stuff like that. So yes. So let me just show you how you can create one. So once again, we are importing TK Enter well, everything from TK Enter and we created new window and then we show it. So right now we would like to create the canvas so I'll just give you, like, see will be equal to new instance off the canvas. So canvas And inside here we passed fue para meters So the 1st 1 is basically the master. So once again this will be placed in the window or at But then we can define two off the most important properties which is with and hide. All right, right. What would you What did you want in a canvas, right? You want to know how wide is it and how high and the hate of the canvas, right? Not not nothing too much more so inside here you can simply type with and then you can assign to it for example, free 100 pixels and and hate. And let's do, like, 200. And yeah, and then what do you want to do is basically show it so I'll just back it up so back and yeah, and parentheses and s. So let me just run this so that you can see that there is nothing too much to see. All right there there will be just a empty canvas, but we will draw shapes later. All right, So, as you can see, there is empty canvas. As you can see, the with off the window is the window is wider than it is saw. All right, so that means this 300 is greater than 200 which make that makes sense. Right? So right now, let me just created a new line. So how to create a new line and add it into the Canada? Well, it's actually quite simple. Simply type in here. See, then dot All right. And as you can see, if you type create, there are a few things that you can create or are. You can create that extracting Gopala Gombe a lot of stuff All right. So let me start of with the simplest one, which is the lie. All right. So, as you can see inside year, you can create line with Gordon. It's so Exxon X two x n right and so on. So basically x one and x X one and y one is one point, all right. And that's the starting point. And then the x n and y n is another point. And that's the ending point. All right, So let me let's say that I want to create a line that starts a deeds up left corner and goes to the Baden right corner. All right, So how do I do that? While simply the starting point is zero and zero. All right. And then the ending point is free. 100 and 200. All right, so why basically means the height and X means do you with All right, so, yes. So let me just run this and actually, let me just add a fill to it. So, Phil, and let's set it to, for example, rat or something that we can see quite nicely. So if I run this as you can see, there is Iran right. And it starts a D top left corner. So that means 00 and it ends a DIY bottom. Right. So from this, you may notice that the height goes from 0 to 200. So down here is 200 up here. Zero. All right, so in the middle is 100 the with goes also from zero to free 100. Alright, at inside. Here we have something like 1 50 All right, so 150. So, yeah, that's the most important thing you have the the excess like this Basically. All right, so it's not like a mathematical graph or something like that. You you basically the y x is gross down. All right, So, yeah, let me also create another line. So create line. And let's say that we want to create this line that will go from the bottom left corner to Dietz up right corner. So how do you do that? Well, the X coordinate is the in the left corner. Right? Will be zero about the y coordinate. And that means the bottom is 200 right? So bottom is 200 top zero and then we want to g 02 right? So that means free, 100 and top. So that means zero. All right, And let me just change the fell off this month's to, for example, Green and let's see how it would look. So if I run this application, as you can see, Ed goes from the bottom left corner to top right corner. All right, so this is probably the most important thing about canvas. It's how you can index these points in there and yeah, and then you can draw all kinds of shapes inside here, and we will draw more in following lectures. So if you have any questions, feel free to ask, and I'll see you next time. 63. Final67 Rectangles: All right. So in the previous lecture, we talk about canvas. So in this lecture, we will talk about rectangles. So rectangle is just a shape that you can place inside canvas, and it is defined by two points. All right, so you might think that direct angle needs four points. But since we have basically the the other two borns can be computed from the two points that you define. How is that possible? Well, you basically create a line. All right, So you to find a line and the line will tell the two points, and the other two forints will basically be computed. Where? D line. All right. And there. So let me just let me just show you how did work. So inside here, I will just create a new rectangle. All right? And let's say that we will do pretty much the same thing s this line. All right, So if I run this application, what happens? Well, we get the canvas, and it will be whole red. Why is that? Well, the starting point basically means this born Andy in the top left corner, and it will grow down to the bottom, right? All right. So that's how we define a rectangle. And how do you compute from these two points? The other two points? Well, basically, the X coordinate from this one and you I co ordinate from this one will give you this point . All right. The Y court in the formless one and the X coordinate from this one will give you this point . All right, so that's basically how you can define a rectangle only why are two points and that's what this what this create rectangle function does basically and thats so let me just show you how we can define a different rectangle. So, for example, this one will start at 100 all right, and it will go only to 200. And it will go from Let's say we have like so let's say, like, 80 and it will go to 1 20 All right, so this will be a kind of rectangle in the middle of the Canada, and as you can see, there it is. So how did works? Well, the starting point is at 180. So 100 on the X coordinate. That means we are in the 1/3 all right. And an 80 in the UAE co ordinate. All right, so that means we are somewhere around, like, 1/4 I think, Yeah. Now know something less than 1/3. Write something more than 1/3. It very much. Doesn't matter, as you can see. Yes. So? So this point is basically defined the first and then d last. So that means this one is defined as 201 20. So 200 basically means 2/3 of the X coordinate, and 1 20 basically means here, and yet it kind of fits. It can fit. So that's quite cool, right? So let's create another rectangle. So inside here will create. Okay, Right, single. And this one will be a bit wider. All right. So it will go from, let's say, 80 to and no, let's. Let's keep the y court in that. Same. All right, so this one will go to 22. 20 and the UAE corden and will be still the same. All right, so the u I co ordinates are saying about the X coordinate changes. So what do you think? How do you x and go will look lack So, Phil will be equal to, for example, green. And let's play this one in front off this one. All right, so if I run this, the wreck tango will be behind this this red rectangle. All right, so the green one will be behind this red rectangle, because you basically the computer basically shows this rectangle, all right. And then he goes to the next line and shows this rectangle So he basically place this new rectangle over the rectangle that he previously shown. So what do you think? How direct single will look like. Will it be wider or taller? So, yeah, it will be wider. Why is that? Well, we change the X coordinate and the ex Gordon, it is basically right now. Direct single starts at 80. Right? So we go from zero. And here here is 80. And here is 100. All right, so it starts a bit sooner, and then it goes of bed more. Right. So, as you can see inside here, there are 2 20 that's here, and 200 is here. All right, so let me also change the rectangle so that it is taller. So how do we change that? Well, we need to change the y, coordinate off these two points, and this one should be smaller. So, for example, let's set it to 60. And this one should be bigger about to demonstrate the changes. I will just make it less bigger, right? So this is bigger by 10 and this is bigger, smaller by 20. So if I run this application sorry if I Rhonda's application is well, look like this. So as you can see on top, there's more space. There is more green than on the bottom, right? And that is because we go from 60. So that means from here, all right. And then this red rectangle starts at 80. So that means somewhere in here. And then the red rectangle answered 1 20 then the green, it's ends at 1 30 All right, so there is a bit less space, so, yeah, that's basically how we can create rectangle. You can obviously place it anywhere you want, and that's pretty much it. So if you have any questions, feel free to ask, and I'll see you next time 64. Final68 Oval, Point: Alright, guys. In this lecture, we will talk about how to create an oil, so that's quite simple. It's basically a Rick single Onley. It iss like like a circle, basically. So if I type in here, create and inside here as you can see the over, we can, for example, fitted inside this red rectangle, all right, and we can make it, for example, white. So if I run this as you can see, that's how d that's how the over looks like basically, So it's nothing too complicated about this one. You basically just Sabti you just create a rectangle, and then computer computes all the points he needs to create an oval from the rectangle that you just passed. So, for example, if I want Onley a smaller while, I can simply put inside here, for example, from 1 40 to 1 60 and then from 90 to 1 10 and this will be quite small over. It will look basically like a circle, and it does right. As you can see, there's a circle, so that's how you can also create a circle, and a nothing the over is good for is to create really small points. So because in the in the DK enter or indeed canvas, there is no way to create just one point from from one year from just a point on a screen. For example, if you are drawing something, you want to just color Abdi points that you are clicking on all right, so only single points. So how do you do that? Well, you do it where over, But you basically do it like a really small over. So if I do, I'm not sure whether you will be able to see this. But if I do like extremely small over so, like this and if I run this, there should be a white dot and even I am not able to see this one almost so Yeah, there's like, really I can see it, but I'm quite sure you will not be able to see this. But if you run this on your computer, you should be able to see a really extremely smiled out. It looks like a dot inside your application, and they're so that's how you can basically create a point. Why are a over and that's pretty much it for this lecture. If you have any questions, feel free to ask end else you next time 65. Final58 Todo List: all right in his lecture. Real crazy to do list. So let's get into that. First of all, I'll m poured so well from the TK Enter, I will import everything all right, and I will also create a new window. So this will be a instance off TK And then I will basically displayed the lindo so same stuff as before. Nothing too interesting. Bad. Then what do you want to do? Well, first of all, what we can do is, for example, changed the title of window. So I think I didn't talk about Ed Bar. You can change the title, obviously, up your window and you can set it to something like to do lists. So, like this. All right. And so does Harry change the title of your window? Now let me find the main part of the application. So the application have a huge list box then, and have a one entry and then two buttons at De Baden. Right? So let me just define delist books. So let's call this one, for example, a content and this will be just a list box new instance of less dogs, which the master will be window And then what we can define. We can define a lot of properties. But for example, I will change the font so that it is a lot bigger. So I can maybe do area you can do. You can do obviously whatever phone do you want. Same same like colors. So I'll just keep it 24 then let's make it bald, because this is the most important part off our application. OK, so then what we need to do? Well, we need to create a new variable where we will keep track off the task that use a road into the entry. All right. So used to write something into the entry, we will store it into the desk variable, and then we will add it to this list box to this content when he clicks on the ad button. All right. So, as you may remember from previous lecture D tasks need to be a instance of a string where all right, and then we can create the new entry so we can call it just e as a entry. Right? It can obviously choose your own name. And yes, so the master will be window and then we need to define the most important property, which is the text, very ever. And this one will be the task, all right. And let's also make the phone a bit bigger. So fund and this one will be also Ariel. And let's make this like 2024. Let's keep the same. Only this time it won't be bald. All right, so yeah, too. And, yeah, so that's pretty much it then all we need to do is create these two buttons is down there, right. So the button be dad, or, for example, button at or I did will be better. So this will be a new instance of a button and the master will be Deve Indo, right? That makes sense. And then what do you want to define? Well, first of all, we want to define the text, and this will say at and then what we need to defy. Well, I also changed, he found, because right now the fund is quite small and since we have big phones on the entry and on the less box D button would be extremely small, right? So I want to change the front also to for example, Ariel and in here, like 20. All right. Yes, because the button have a batting. So it's it's okay. T to keep the phone size a bit smaller. All right? Yeah. And another thing that I should define is the callback, right? Saudi command. When? When A When the button is clicked. So what will be inside here? Well, I will just for now, keep it blank, and I will get back to it. All right. So let's define also the delete button. And this one will be also a new instance of button. We'll have a window, and the text will say Just delete. So like this and he phoned. Will Bill will be bringing my same. And I can also come help the basic command and U. S O. Right. Now, let's take care of the most important part, which is the command. So while you want to do well, when we want to click, usually we want to call a function right. But as you may remember, from previous lecture, we have a lumber expression, which is just a simple function and what we are actually doing when you click on the add button while we just add whatever is in the task. Variable to the content. Right. So that's not too much work. We could do it. Why? One command, right? And yes. Oh, Lazutina so well defined a new under expression. So well, basically defined a function here. We don't define the function somewhere in here. All right. And yes. So this one will accept the content as a harem, either. Right? Which is just which will be set to the content to discontent. All right. And yeah, and then it also accept the task, right? We need to be able to get the task, so yeah, I will just call it ask, and I will assign it to the task value. So to this variable and what I want to do Well, I would like to add the task to the content. And how do I do that? Well, I simply have been here content dot insert. All right. And this will basically insert some string into D basically into the less box. All right? And first of all, we need to define the index where we want to put it, and we want to put it at the end. But how do we know the end off the content off the off this instance. Well, we simply type in here and and computer will take care off everything for us. All right, So then or we need to do is simply its i d get the d text from the task variable. So in order to do that, we simply type task that get, and this will return the text that is ridden into into the entry. All right? And so that's basically the add button taken care off. It's quite simple, actually. And there's another thing that we can do is define the delete button. Well, not only can about will do so bring my same thing in here, So we will basically take the Lambda expression as a function. All right, because we only need to delete something, So that's not too complicated and what we need. Well, we actually need only delist books, right? Okay. So I'll just call it content, and I will assign it to the content. So basically to this very ever. All right, so this variable will be bind it as a content inside the Islam, that expression, and then all I can all I need to do is simply type in here, content that delete. And inside here. What do you want? Well, we want to the lead the element that is selected. All right, So the idea is that user clicks and it deletes these selected item. But how do you know which one is selected? Well, simply while this anchor. All right, so in here, basically computer, if you type in here, Anchor Computer knows that he needs to take care of the selected one. And so that's about it. Right now, all we need to do is basically placed these elements somewhere in our window. So there's not to complicate it. If you feel like you can get the last part going all by yourself. It's good thing if you try to pause the video and try to do it on your own. All right. So yeah, so simply type in here the content dot grit and will place it to the to the top. Right? So the row will be zero, so the row will be zero. And the column We'll be also zero, right? And then what we need Well, we need the current span. So come span. So That means basically that this our men wills will be in two columns together. Right? So basically two columns. And yet because we will have, like, this whole list boxes than underneath will be also the entry. This will also take two cells, and then there will be one button in one cell and other button in other cell. But these buttons will be on the same line. All right, so, yes. So this will be to all right. So because we owns two cells and there, then we can also define something like batting. So betting off X will be, for example, five pixels and bending off. Why? Will be, for example, 10. All right. And yes, so does basically the the list box taken care off right now, or we need to do its place. The entry So e that great. And inside year, we wanted to be on the road one so directly underneath this content. And yet the cone will be also zero right, because we wanted as left as possible. And then what do you want to do? Is also at the count span and these two, so I'll just copy face that to save some time. And they're so then or we need to do is place these two buttons the at and delete button. So at that Great. And inside here, we will have the role too. So this will be underneath the entry, all right. And the coming will be zero. So come will be zero. And then what we also need Well, we can define the batting for this. Yeah, Was the fanny patting for it so that these elements are not tied up together and they have a bit off space? All right, So, for example, the X can be five, and the while it's let's make it a bit bigger, all right? And that same goes for the delete button, so I'll just copy, face it. So inside here lbd delete and what we want to change for the delete button. Well, the buttons should be on the right side. All right, so we will change the column from 0 to 1. Okay. And that should be it. So if I tracked around this application, as you can see, it looks quite Butte. Well, reasonably good. These buttons look terrible that if I type in here something whatever and he'd this ad button. As you can see, there is the task, and something else is also added. So cool. And they're So what I can also do is delete something so I can select it and then delete Cool. That also works, right? So, yeah, that's basically working application right now. D add button doh looks quite off since the delete button is a lot bigger, A lot wider, right? So let's also add some batting to this Dutton. So in order to do that, we can simply go back to our editor and find the red button. That's right here. And we can add depending. So betting on the X coordinate. All right, So you want to change the with and we like to add, for example, 30 on each side. All right, so 30 and let's see how it looks. So if I run the application, I get an error or right? I forget about comma inside here. And if I run this again, it should work. Yeah, it does. And that's against CD. Button is a bit bigger. All right. So they look pretty much the same. Same with so yeah, that's pretty much it for this lecture. If you have any questions, feel free to ask End. I'll see you next time 66. Final59 Text Editor 1: all right in this lecture wheel created text editor. So let's get started. Simply. First of all, let's import everything from dtk enter. So from decay, enter implored everything all right? And let's also create a new window. So window will be equal to be new instance off decay. And let's show it. So staying same stuff is before a Yeah, you probably know. And yes, so and I think that we want to do is defined the menu on the top. All right? So simply create a new instance off menu, which will be the main menu. All right, so this is a new instance off menu. The master will be window. All right. And that so then we also need to convict. So, window, that gonna thick config the menu. All right, so conf IQ and inside here retyped menu. And we said it too. The main menu. Right? So main menu like this and I wrote comments. Yeah, so, like this And another thing that we need to define is the sub menu. Right? So we will have a file in there, And when user clicks on that, there will be, like, safe, open and stuff like that. So we define a file menu, so this will be also a new instance off menu. But the parent will be main menu like this and the and we will basically added to the main menu. So main menu dot at cascade, and we add their the label, which will be the file and we also passing daddy menu. So menu and this will be the file menu like this and cool. So right now, let's add some stuff to the file menu. So found menu dot at command and what we want to add. Well, we would like to add the the first of all, probably the open right. Open is the 1st 1 I think always, and the command will be, for example, just open file. So this will be just a function that we will define later on. All right. And then we will also add file menu, the at demand, and this will say safe. All right, so label equals safe and the command, the command will say something like, say, file. All right, so these these are functions that we will define later on. All right, so let's also add the separator So foul menu that at separator so dot at separator And let's also adds a and no, for example, close. Well, I don't wanna program functionality to all of these bad. Yeah, certain just so that it looks a bit professional. All right. So I will just add the last one which will say close. I believe that this is the menu to do. You have in pretty much every application. Oh, my God. I can outside. So this one and this one, all right? And s So you can obviously add another thing, like edit or stuff like that. I will just, for example, at a new another one. So, for example, main menu dot at just a command, something like help or whatever. Yeah, you can do whatever you want. So So I'll just add the label help cool and eso Then what we also need. Well, we also need the huge textbooks in which the user can see the file and right into the file . Right. So how do we define that? Well, it's great. Simple, actually, we can simply name it somehow. So, for example, content and this will be just a new instance off text object from dtk enter. And this is basically a huge textbooks in which user can read so it will be placed inside the window. And we can also define the with off the off this whole text area, which will be, for example, let's say that it will be 100. All right, so 100 characters basically and they're So let's also display this so content that grit and this one will be, for example, rose zero and gotten zero socom zero. And let's also add deep batting. So, betting on X, let's say five pixels and betting on why will be also five cool. So if I try to run this right now, we will get an error because I didn't specify these functions. Right? Body? Yes. So that's pretty much it for this lecture. If you have any questions, feel free to ask, and I'll see you next time 67. Final60 Text Editor Functionality: All right, so in this lecture wheel program, the functionality off this application. So this one will be a bit more interesting. And yes, so let's get into it. First of all, let me just inboard Well, none. We'll do that later on. All right. So first of all, let me define. He functions. So, for example, 1st 1 will be the open file. So this except snow para meters and what we're going to do Well, we would like to ask user for a file. So we would like to open the the open file dialog. Right? So the dialog that opens up user simply select a file and he loads it. So how do we create that? Well, we can simply tude at using the files. I awoke a from dtk enter. All right, so we will import from dtk. Enter. We'll import the file. Dalek. This one is not imported where the star or I do have to explicitly imported like I do right here, all right. And this will basically allows us to use the file dialects that are defined. So then what we can do is simply typing here The file that look Dodd and inside. Here is the ask open file. All right, So ask open a file and dismal Basically open di di di a work for you. So, first of all, you need to define the moat, which will be read, right are And then you can define, for example, a title off the window. So title, which will be, for example, open or select file select file. And then what we can do is also defined the file types. So, for example, file types. So this one is extremely important. For example, if you are working with I have no images or something like that, you probably want to define the file types that are allowed, right. So let me just put it on the next line, and the file types is basically a list. All right. A list off Audie couples that you can have. All right, so inside here, you type the the 1st 1 is basically what it says. So all files, for example, and then you can import everything. And how do you import everything? You can do it like this. So star dot star All right, that means basically every file possible. You can also import for example, only text file you can import, right. You can change. So this is basically what is shown in the dialogue, and this is basically the extension that is needed. All right, but I'll just open everything. Whatever, and eso this will basically open a file for us. All right, so then we will have Indy t We will have defiled that we just we just opened and then we're going to do well. We would like to set it to this content, right? So to discontent element. So how do we do that? Well, the content have a method that is defined exactly to do that. And it is the insert method, and it takes a few para meters. So the 1st 1 is basically the index where we want to put our text. So, for example, to the end, and then is the actual text that we want to add, So that will basically be the tea that read. All right, So we will read everything from the file that we just opened and put it to the end off our content. All right, the I think that's very much. It's so right now, it's also closed the file. All right, so for you. And we will just hope for now that the fire will exist and everything will work. Body, And then we will take care off the exceptions. So if I run this all right and we get an error that the safe file, it's not defined. So I'll just basically take it out and also the scammer. And if I run this again, the application is shown. And if I click on file and then I cook on open it automatically asked me to select some final to open, right, so that this quite cool. And as you can see in here is the all files, right? So that's basically what we defined in here. So the file types and there So, for example, if I select something, it works, it works. That's the file that we just opened. And there, So right now, we can edit it out. We can do all kinds of stuff inside here. We can ride, we can do whatever, but we can not safe. So how do we how do if exact, how do we save the file? Well, it's quite simple, actually. First of all, let me just put back D D command 40 safe. So command will be safe file so safe file and lets the find the method or function that does that. So inside here I will just define the safe file method, and it will basically just accept nothing and what it will do. Well, it will once again open a file dialog. So, five, do I look and it will ask to save the file. So ask safe file, all right. And demote will be right, because we want to write it right and the extension so we can define a default extension. So default extension. And this one will be, for example, ttxt. All right, so that's txt. And yes, so then it basically opens up the file and what we want to do. Well, we would like to write into it so well, basically, like to do f dot Right? And inside here, we would like to take all the content from the from the content right from this element. So how do we do that? Let me just first define the variable before, so I will do it separately. So inside here I vote basically five de text user road, all right. And we will get the text from content. And how do we do that? Well, we will simply take the content, then get all right. So get. And what do we want to get? Well, we would like to get everything. And as you can see inside here, it basically takes two indexes. So from index wound to index to and the index run is basically we owned the starting position, which is one that zero. All right. And the index to is the end. All right, so the index to is the end, So simply type in here the end, and we also need to change it to strength. All right, So string and put this into parentheses or red. So right now, we have indeed text use road in this very ever. We have the actual content off the window, right off the text. And yes, so right now, we can simply just write it. So text use the road and we write it into D file, and then we close the file, so file that close like this and let me run the application. So if I click on these safe, even though I didn't write anything. We get an error. Okay, So what? What does it say? So if I just close the application, It says all right file. And I'm a blind. What happens in here? Save us. All right. Options must be default extension. All right. I made a top typos. Sorry about it. Extension. So if I run this again and I type something in here So, for example, some nonsense and he's safe. It opens up a dialogue, so that's quite cool. And right now I can say something. So, for example, my Safed file like this. And if I save it, so if I save it as you can see it, it is in here, all right. And when I click on that, it actually opened the content off the off the text box that we have in our application. So, yeah, that's that's also working, so that's quite cool. So this is pretty much it for this lecture. If you have any questions, feel free to ask, and I'll see you next time 68. Final61 Text Editor Functionality 2: all right. So I almost forget on the close. So let's also make it work. So inside here, real time d commend. And we will Essentially, it's something like Close window, all right. And yes. So let's also define this. And this one is quite simple. So inside here, for example, we can define a new function called Close Window like this. It will accept no para meters and what we want to do. Well, we would like to close the window, and in order to do that, it's actually quite simple. You type just window and then destroy all right and empty parentheses, and it will basically just closed the window for you. All right. And another thing that I want to do in this lecture is basically take care off all the problems that can occur when we are working with these files, right? So sometimes can happen, for example, with these safe file dialog that the user, I don't know, just Greg's on d cancel, right, So doesn't save the file. So first of all, we will check whether the file is existing. So what if it is actually existing or it's more or less whether it is not existing. So if it is not, that means the user just somehow cancel this dialogue. All right, so this dialogue that's being shown, he hit the cancel. So what is stored in this variable? Well, it is just not so we checked. Gravity file is none. And if it isn on, we simply return from dysfunction. All right, so we will not execute all of this coat down below, all right? And, yeah, so you can also return from a function without any value. All right? I'm not sure what I mentioned it before, but I'm mentioning it now, So this is basically just Hey, I'm done. This is just exactly like the break statement, all right? And eso den, there can be some errors occurring in here, right? So we'll just for sure, we will just put it into the try statement. So we will try all of those. All right, So both both of these and then we will do the except So accept. And if something happens, we will just, for example, brained Now, I know you cannot safe the file, all right? And finally, we will just close the closed the file. All right? So finally, we will just close the file like this. And yes, so that's that's about it. That's about it. Because right now we don't have to check whether the file is existing, because if it was not, we would return at this point. All right, So this code would not be executed, so that's all right. That's just fine. And there. So let's also put the these thing and to try and catch an and accept. Sorry. So how do we do that? Well, inside here, we can just put everything in try. So try and inside the Royal basically put both off these lines into the try statement, all right? And then we will simply do the except So accept. And if something goes wrong, which can happen, we want to sprint. Um, cannot load g file. All right. And yeah, and finally, we will just close the file, So finally, Well, we will not just closed the five. Well, first of all, check whether defile exists and we can do it just like this, and then we can close it. So just like that, and yeah, All right, so this will basically take care of the checking whether the file is actually existing, because sometimes can happen. Dad, the user. I know the defile. It just doesn't open. For some reason, something goes wrong. All right. And DT is just nothing. So we check whether Dee Dee exist. If it as well just closed the closed the file. And yes, so that's about it for this lecture. If, if any, questions. The application is just right now working. Everything is working except 40 help. But I'm not sure what to do with the help, but s So that's pretty much it. If you have any questions, feel free to ask in. I'll see you next time. 69. Final69 Paint: Well, hello, guys. Send well countered his lecture. In this lecture, we will create the paint. So let's get into it. So first of all, we'll import well from the decay enter. We will import everything. And then when we want to do well, create a new window. So this will be just a new instance of TK than we also want to show the window. So many nuke like this. And inside here we also want to create he canvassed in which we will draw so cannabis and so be a new instance off canvas like this and as a master will be the window and the width and height is up to you. I'll just keep it for example at 400. And the hate will be also about 400. Sorry, 400. And that student I will be just bagged the cannabis. So Peck and I will not specify where I want to pick them. There will be only canvas in this window. All right? And they're so another thing that we need to do is define a event for the canvas. So how do we do that? Well, first of all, we need to bind the event. So basically, the canvas allows us to buying some different events. Like, for example, when user clicks, we can do something. But when user I know holds a mouse, right, holds the left button on your miles and simply somehow do some motion over the canvas. We can also bind an event to that. We can also bind and event to different buttons, right? And yes. So how do we do that? The most important thing is the bind method. So the bind method, basically, except a strength which will define what event we want to bind. So, for example, a string like this. So, for example, like this button one. Well, basically bind the events that user clicks. Why are the left button all right? And the button to is 40 middle button and the button free is 40 right button. So, for example, like this, this would be 40 middle button, and this would be 40 right button. All right, but I'll just keep it for the like button. And then what we also do is defined a callback. So basically a function that will be called so inside, I will just call it go back And right now, let me also defined the functions so defying the callback, and this one will take some arguments. And what are the arguments? Well, what do you think is the argument off a mouse click? Well, where the most clicked. Right. So some coordinates some extent. Why? Coordinates off the mouse. Click. So inside here, I will simply type in here the event, and yeah, And then what we will do is simply brains de coordinates. So event that X and then event, Dad, why? And if I run this application, as you can see, a window shows up, and if I click somewhere, right, So I'm clicking somewhere in the application. And as you can see, it tells me a co ordinate. So inside here is the for enforced. So that means somewhere and eats up left corner. As you can see, there are small numbers, and inside here will be the big numbers. All right, so 404 100 is the with off our canvas and s so, as you can see down here are some big coordinates. And right now we can use the callback to basically create a drawing. So what happens if we, for example, draw a point where the over somewhere where the user collect So we can do that right inside here. We basically have the the coordinates. And if we want to draw a over, we simply need the scored a nets. And yes, so let me just draw it. So we will take the canvas. So see, And inside here we will create a new over already. And let's make it a big, bigger So event that X. So the starting point will be, for example, minus five. All right, so the so the over will be quite big. All right. And the ending point. So event that why will be also minus s. Oh, sorry. That's the y. Coordinate of a starting point. Still, all right. And then the ending point will be in the event plus that X or write to the X coordinate off . The ending point will be a five pixels bigger, and the y coordinate will be the same. So event, Dad, why will be also blast five And we can also define the fell and this can be green or I know it can be also another thing I forgot to mention is that you can use a RGB model so simply inside here, type hashtag and then again type some color in RGB. So, for example, like this one or whatever. So if I run the application right now and click somewhere as you can see, there is a point, right? So I can just clicks I can do quiet, simple stuff, some simple clicking and I can draw I know what I can draw, but yeah, So there's how you can create a simple call back that will basically praying to the event. So if I just move it like this so that you can see it and let me just get rid off this stuff. So what you can also do is create a callback. Dad will basically take care of the emotion. So, for example, when we click and keep the button clicked and move around the canvas, the motion, the motion will basically detect that. And each time we move, it will call the call back and with the with the position off the movement. All right, So how do we do that? Well, we will basically bind another event, So the motion movement is simply like this So inside here it's Abdi Button. So for example, Button one and den motion like this. All right. And inside here, it could be also button to and button free, depending on what button you want. So development for is the right, and he button to is the middle button. But I want he left one. And inside here you can define the callback. So, for example, draw Yeah, just draw. And inside here I will define it. So the fine d draw and inside we will take the event and what we want to do. Well, each time we draw something, we would like to bring much do the same, right? So we will well, basically add a new over into the canvas and yeah, and let's maybe keep this wanna, for example, or I will just keep it same way. But I'll just change this one to, for example, FF Let's make it what or no, let's make it black. I want to want to so like this. And so this is basically bled. The f f f f f f would be white, so yes, so let me also print d co ordinate off dysfunction. So that you can actually see this so trendy Event X and the event. Why so like this and like this? And also get rid off all of these points that we already printed who had a clear. And if I run this, we can see the window. So if I click, this goal back gets to be called. And if I click and draw, as you can see there is the emotion and I can basically draw whatever I want on Lee, I have to draw it slowly because if I suddenly like, do some quick movement, the computer is not is not fast enough to basically call the function each time I can I because the movement is so fast, right? So yeah, and still, if I click, I get a different right. So that's another thing. And what do you can do is, for example, create a rectangle inside here on a click or whatever right? Or with the left mouse, you can create a rectangle. So with the left, my let's actually do that. So see dot bind And inside here we want to bind the left mouse movement so it will be basically be free and its side here, it will be just emotion. All right, so, like this and what we want to do is draw a rectangle like this. And how do we define that? Well, simply type in here, draw a rectangle, and it will accept a event. So event and what we're going to do Well, you would like to simply I'll just get rid of this sprint and we would like to just create a new rectangle, and these coordinates should be Well, actually, we need the first co ordinate and the last quarter. So demotion is not quite good for this. We would actually, we would rather take the click, right? So we would like to take the first click and then the second click. And if there's already a first quick, we would like to draw a rectangle. So yeah, let's do that. This one will be a bit more complicated. So anyway, we can do that. So, for example, on the button free click. So that means on the left button click. We will call this function. And inside here we were basically define a bullion. So up here we will define a new Boolean variable weather. We want to draw, all right, and by default, it will be set to false. So by default, we only want to take the first point and don't draw anything. And if it is true, we would like to draw from the firstborn to the second point. So inside here, I will also keep the X one and the Y one. All right, so why one? And this will be the starting point. So the idea is that you click with your left button once. Then you will said these said the starting point. So these two and then you click for the second time, and it will draw a rectangle from this starting point to the point where you clicked 40 seconds time. All right, so, yeah, let's do that. So inside here we will First of all, check whether the draw is false. So if Well, if draw is true, what we want to do, we would like to create the rectangle. So see that create a rectangle and inside here where we want to start. Well, we would like to start at X one A and Y one. All right. And then we would like to draw it sue the event coordinates. Right. So the event that X and the event that why so this this is our ending point. So the point where we clicked and we can also change the felt So, for example, he fell can be just are no threat, all right? And yes, so bad if we And if the drawn iss false so bad unfolded this false what we need to do? Well, that means this is the first, like so we need to set these x one and y one and said the draw to true. So the X one will be equal to event that X and the why one will be equal to event. Sorry, events that why? And then we need to set the drawer the true. All right, so if I run the application, as you can see, it takes a while to compound. But as you can see, if I left click somewhere inside here. Okay, I get an error. Draw. Very bow before. All right. All right. I'm sorry. I made a mistake. So inside here. What is happening? Well, we basically are using the draw variable and the x one and the x two or sorry, x one and d y Juan and that these are global variables. All right, so we need to tell the function that we need to tell the function that hey, the draw and the Exxon and the way I want is basically a global variable. So inside here we will tell that so global draw, then X Juan and the U Y. One. So, like this. So that basically means that the X one and he y one will be your reference from here. And he draw also. All right, but yes. So right now, this should work. So if I run this again and left click somewhere and then left click again, I get an error. It's all right. I made a mistake in here, So I meant to say why wound? So 40 last time if I run this again and do a left creek and another left big as against either Xaver Tangle appearing all right, but yeah. Then we get in back because right now, when I clicked, it just creates new a new rectangles. All right, So what I want to do is basically after I draw the rectangle, I need to said the draw to false All right, so that we can then define a new rectangle that we want to draw. So if I run this application again hopefully for the last time and I do left click and another life break that school And right now I do another and another yet dead works. 70. Final70 Paint Fix: But as he may notice, you cannot draw light. So if I'm trying, I'm trying right now to draw a line. But it doesn't work. So why is that? Well, inside here, Use simply need to put this one above so that there is the problem, that we have thescore backs right after. And then we somehow defined a variable Sodertalje problem. So if I run this right now and hopefully 40 or has time, everything should work. So if I create a new rectangle that does work cool and if I create dots that also worked But somehow I clicked somewhere out of the window I can also draw lines. So yeah, there's basically it.