Python Beginners Programming Guide | Jack Donaldson | Skillshare

Playback Speed

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

Python Beginners Programming Guide

teacher avatar Jack Donaldson, Game Designer & Programmer

Watch this class and thousands more

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

Watch this class and thousands more

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

Lessons in This Class

27 Lessons (3h 29m)
    • 1. Introduction

    • 2. Why Python

    • 3. Installing Python & Pycharm

    • 4. Variables & Data Types

    • 5. Problem #1

    • 6. Lists

    • 7. Condition Statements

    • 8. Problem #2

    • 9. Problem #3

    • 10. Mathematical Operations

    • 11. String Formatting

    • 12. Problem #4

    • 13. String Operations

    • 14. Problem #5

    • 15. Loops

    • 16. Problem #6

    • 17. Problem #7

    • 18. Functions

    • 19. Problem #8

    • 20. Classes

    • 21. Problem #9

    • 22. Dictionaries

    • 23. Problem #10

    • 24. Libraries

    • 25. Scope

    • 26. File Handling

    • 27. GUI'S

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

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





About This Class

Learn to program with no previous experience in just a few hours!

This course aims to teach students with no experience, the fundamentals of the programming language Python. Python is widely used across industry and is found in almost everything you use, from websites & apps to machine learning & ai. It's robust nature and simplicity to learn is a driving factor towards its massive uptake by both students and professionals. 

Python is easy to learn, completely free and great for beginners.

This course will teach you everything you need to know about it so you can start creating basic programs with ease!

Concepts Covered

By the end of the course students should have an understanding of the following concepts:

  • Python & Pycharm Installation
  • Variables
  • Data Types
  • Lists, Arrays & Tuples
  • Mathematical Operators
  • String Formatting
  • Condition Statements
  • String Operations
  • Loops
  • Functions
  • Classes
  • Dictionaries

What You Will Need

  • 2-3 hours of free time (This is dependant on skill level and speed)
  • A modern PC / Mac capable of installing and running Pycharm (See specs here)
  • An internet connection to download Python and Pycharm

Meet Your Teacher

Teacher Profile Image

Jack Donaldson

Game Designer & Programmer


Hello, I'm Jack. I have been making games for the past 5 years using Unity and have a thorough knowledge of C#, C++, Python, HTML, PHP & Java. Please check out my courses on Game Development & Programming and tell me what you think!

See full profile

Class Ratings

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

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

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

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


1. Introduction: Hello, We're on end. Thank you for checking out my pipe. In course, on skill share. This is a great course. I've spent loads of time developing and testing and hopefully refining it down so that it's simple and straight to the point for beginners. Python is one of the most popular programming languages to date, and it's easy to use and learn is great for beginners to get started. We initially start by installing Python, and we use an I. D called pie chart. This is all free, and all you need is a computer and an Internet connection. We then learn about variables and Darla types. This maths string formatting condition statements like if and else, and we learn about manipulating strings and texts within. Delve into the more complicated concepts such as loops, functions and classes. And then we finish it off with learning about dictionaries. This course teachers by doing, I do lots of practical projects and walk you through how the code works. Step by step toe, hopefully build a good, fundamental skill for you and hopefully you will benefit from this court. It was so please stick through it. Pipe of programming is extremely useful. And no matter what you're doing, I hope that you enjoy the course and please leave a review or follow me if you want to check out my other courses as well. 2. Why Python: Hello, everyone, and thank you for checking out my python introductory course for beginners. Ah, what is by thin? Well, it's a programming language that is used widely across the world and is really, really good for beginners. And introductory is people who haven't done programming before, and it is really powerful language. So don't be worried about not going too much in debt, because this language is used widely by big companies such as Google, Spotify, Yahoo, Um, and as such, there is a high demand for people skilled in this language, and it also will teach you the fundamentals that can be transferred into even more detail and complicated languages like C Plus Plus or C Sharp or Java. Ah Python is the fastest growing programming language in the world, and this is due to many factors. But it's popular both among software developers, mathematicians, teachers and students. This is because of its diverse capabilities and both its ability to be simple and extremely date out and powerful. Ah, it's simplicity is because of its ability to be very close to English, which makes it easier for people to pick up, and this is why it's referred to as a high level language, which means it's easier and closer to English, as opposed to lowland level languages like C Sharp or assembly Ah. This allows problems to be solved with fuel lines occurred. Eso developers aren't having to worry about formatting and miscellaneous perks off the language toe Weber, and you can simply just get what you need to do right down, and it will run very quickly for you. It's extremely diverse and cable, and because it's such a powerful language, it has been used in multiple different industry areas. It's used in mobile and desktop app. Sweb Development, automation and Testing. AI. Machine learning is a big growth area for it, and because of its capability to both interact with lots of different languages. It has really become such a popular language that's been used in hacking. Um, and data and statistical analysis is another big area with modeling. And that kind of thing is so you really can do a lot with this language. And this course is really designed to teach you that, um so a little bit about me, I have Bean, a software developer for over six years, and I am flowing in a lot of other languages, including C Sharp on and C plus plus Aziz well, as Web development languages like Haiti, Mo and see as s as well as PHP. Now, I've just started a whole bunch of different words. You don't know what they mean. Don't worry about it. We will be going through this course right from the basics. If you have some previous coding experience, then I would suggest you check out a more detailed course. But this is really for people who haven't. I use python before and we'll go from the basics right through two more detailed aspects off it. So hopefully you can end up creating lots of different programs. Eso this course will teach you all of that. And hopefully you will enjoy it. So thank you. 3. Installing Python & Pycharm: hello Runs. So now we're gonna be downloading and installing python and pie chart. So first things first, What I'm going to get you to do is open up Google or your relevant web browser, and you can simply just search Python. Ah, and it should be the first link there already. Cut open here. Um, and you just go straight to the download section and you'll say that I have, uh, downloads python 3.8 right here. Obviously, if you're on other operating systems, you can click the relevant links. If you want to make sure that you don't have any issues. Ah, with different versions, you can download 3.8 by just going down to this table here if you're new. Uh um, diversion number shouldn't matter too much as long as you have three in front of yours because there is major issues or differences between python to and Pyfrom. Three eso Just make sure that you're sticking with python three and not by than to cause python to our will be considered out of date after 2020. So make sure I want you hit. Found this bun. Just click download and you should say that it starts downloading eso. Once you've done that, you should find it in your downloads photo. Ah, and it should just being executed all so you can just run it. Ah, and you should get in install or api. Nice and simply you say something similar to this I I've already got it installed. But when you're doing this, make sure you take the ad python to Path Jack Box. Otherwise, you'll have issues when we install pie chart on. And then you would just click install now, But I already have it installed, so I'm not going to do that. Um So once you've downloaded and installed python, what we're going to need is pie charm. So this is just ah, an I d. So what this means is integrated development environment. Now that really doesn't help much. But what essentially that is is a program that we can use to edit our code. And it will also give us other features like ah, auto complete and syntax highlighting, which can be very helpful. And a lot of developers do use ideas. So pi charm is really popular with Piven. Ah, you can also use other ideas like visual studio at which is also very popular. Or you can use the import python one, which doesn't have very many features and would technically be Justin editor. None idea. So our pie charm is free for just hobbyists and students and the community, Um, and for non professional purposes. So you just click the download button and I'm just going to download the community version , which is free. And it should take you to this download page which will just download Ah, simple exit. And once that's downloaded, you should be able to just run that and you will have no problems, okay? And one sets downloaded. You should find that you have the pie charm community execute herbal, and you can just doubled to have that open it. Now, it doesn't matter if you have a more up to date version of pie charm. Things shouldn't change too much. It's only really gonna be the python version that matters. Esser. I'm just going to get next and I'm going to select my custom destination folder quickly because I have mine on the second drive. But you don't need to do this if you don't want to. So Once I've selected that, we can just click next on, and I'm just going to credit desktop short cut and make sure to take the update path variable checkbooks as well. And also, it's very helpful if you make it so everything with the dot pile on the and opens in by charm. It would just fix any issues you have later on when opening up your pipe and false. So just click next in store and would just wait for that quickly. It shouldn't take too long. I have, but I'll be back when it's done. Okay, so now that's done. It will ask you to restart, so just quickly go ahead and do that, um, ongoing tribute later and just hit finish. So then I'm gonna quickly reboot and load of punch home. Okay, I've opened up I John, for the first time now, I'm just going to stick with the light theme. Ah, and click next. Ah, and it's gonna ask us for some plug ins if we would like that. Ah, but I'm not going to worry about it too much. And I'm just going to click, start using pie chart, and you should see that it opens up this welcome window. So what we're gonna do years click, create new project, and we will get asked for locations and a no. So I'm just gonna call this tutorial project. Ah, and there are other options you can do is well, uh, but, uh, you should only have if you have issues later on. We're saying that Parsons not found or whatever you can just adjust the settings you used here, for example, you can see it's automatically detected my install of python eso. That shouldn't be an issue. But if you do have issues with that, you can set it all up here. But I'm not going to touch that. I'm just gonna hit, create, and you say that it slowly loads up the project and we should be ready to go eso once that loads. Okay, so now that pyjamas loaded up, what we're going to do is right. Click in the file Explorer here on patrol project click New Patent file. And I'm just gonna call this one main and hit Enter. And you should say that it opens out this python follow created, um and you can see it on the left hand side here. Now we need to add a configuration that toes, uh, pi charm to run the phone on. To do this. What we're gonna do is click ad configuration here, press the plus button, select python, and I'm just gonna name this run main script, and you will have to select the python file to run s. So I'm just going to select a main DuPuy, which we just created, and you should be out of hit. Apply. Okay. And you should say that it appears here and we can run the python far, which is empty the moment. And we get a console window. He with no errors. Eso that's it for installing pie charm and python. And if you have any errors, make sure to leave a message blow. Now, just to check that this is running properly. Once you have your rain run mains, great configuration selected, we're going to just typing up. I then felt print and then, uh, open some round brackets and then put some quotation marks in here and we will say hello, world. Now what you should be able to do is save it using control s and hit play so you should find that the console window runs and you can see hello World printed here. So that's just telling you that pythons working properly and the commands working as expected. So that's it for this video and the next one, we would deal with data types and variables. 4. Variables & Data Types: Hello, everyone. And welcome back to this video and we're going to be talking about variables. So, first of all, what is a variable? Variables? Ah, containers that hold information. Ah, their sole purpose is to label in store data in memory. So essentially what it is is it's just a way for Asa's people to tell the computer to find a place where it's stored something. For example, Ah, if we needed to store some age, we would have a age variable. But we would then be able to set the age route throughout a program. Ah, and it would. We would ask the computer for age. Ah, and essentially the computer. The maps age to the location in memory and returns its value. So essentially, variables are just things that we make up that have values and hold information for us. So if you understand that concept, then everything else should be quite easy. But you should pick up what available is throughout this course anyway. Eso there different types of variables that we will be using throughout programming, and this is common across all languages. Eso they need to be given a tight, for example, in languages like, say, shop. Um, you have to give them a type. Where's Python is quite lenient in not having to define it, but it will give you errors if you don't use the right type of variables when performing specific functions. Eso This type is determined by what we want to store in. It s O for example, if we wanted to store words or letters, we would use TheStreet or text donna type, uh, or if we wanted to store numbers, we would use the integer data types and so forth. So depending on what you want to store, will depend on what time I thieve. Variable is so there are different types of variables. Ah, here, some of the most common once their 1st 1 is string, which is words or letters, um, or text e g a person's name, for example, John. Then there is inter GIs, which are whole numbers and can be a person's age. Like to. And then there is floating point or floats. Ah, which are decimals, images, the whole numbers and floating points of decimals. For example, two would be an injured. Where is 26.5 would be a float For that reason, that's another common data type is bullion, which is just a ball, which is just true or false. So that's another one that's also used fairly often. So, for example, ah, if we set a variable user name equal to Jack, it's a string. And this is because, Ah, yes, we wanted to be a string. But the way we tell Python that it's a string is by using quotation marks. You can also use single quotes, but they need to be surrounding the text to tell Python that it's a strength. Otherwise, you can ish error if you don't include these strings. So for so we're sending this variable using him equal to this string Jack. Another example is this variable age, which has been set equal to 23 because it doesn't have the quotes around it. It's not considered to be a string. Ah, and it's also an integer in this case because it's not a decimal point, but just to bring our some cases. If you were to put quotes around 23 it would treat it like a word or letter, and therefore you couldn't do math on it, so you just need to be careful about the differentiation that was technically 23 come being into and a string. But in this case, because it doesn't have the quotes around it, it is a indigent. So an example of this is in Python. We would use the print command followed by two brackets and then inside of this. But we wanna print is the variable user name. So this will be Jack. Plus, now we want to add is in the middle. So be Jack is And then we want to add the age on the end. So we would say 23 here thought because it's a number we would need to convert it to a string using the S T R function are going to get more details about that later. But essentially, this would print Jack is 23 without the quotes displayed him. It's another example is if we had a variable courtside wantonly said it equal to 10 inside to equal of five. Because these have quotation marks around them. They are treated like a string. And because of this, if we would have print Ah, if we were to try to time side one by side to, for example, to get the area of a shape. This would give us an error because they aren't numbers recognized. His numbers there recognizes words or letters so Python would throw on air of because of this type of thing. So the way that you would fix this is if you got rid of the quotes on and then you used at this print statement you shouldn't get year era because they inter jizz and just for clarification. This asterisk e means times in part, and we're going to math operators a bit later on. So this would be 10 times five, and this would print 50 to the console and wouldn't given era eso to change between variable types. Ah, we can use the following methods so evil. What it will do is it will take what is past in between the bracket. So, for example, if we put 23 in here, it would then turn 23 into a ah number and in this case, an interview. If we were to put 23 in quotes, it would turn it into a ninja duras Well, so ive out takes arm string or indigenes or floats and turns them into the proper data type . But this will, if it's 23 point to turn it into a float. So this will I work out what is the best start of type and set the variable to it so you don't get any errors the next one is into. So this will turn whatever it is inside it into a number. If, for example, you put in something that isn't a number and it tries to turn it into one, you will get narrow. So if you put in Jack, for example, you would get narrow because it is in a number and it can turn into one. Also, if you put enough float or decimal, you would you would get it error as well, because it only can turn strings to integers or introduced, introduced. If you were going to do that, the same thing goes for string and float. They will only turn them into that that specific variable time. And if you pass in something that isn't relevant than it will throw an error. So um, that's it for variable types that we would jump on into Python now and I'll show you what I mean by these. Okay, Now we're in. Python will get started with making some variables as examples. So I'm just going to get rid of l print statement we made earlier. And we're going to just try and rewrite the code we saw in the slide. So the first thing we're gonna do is make a variable cord name, and this is going to be equal to in this case we're gonna do to quote because it's gonna be a string or a letter or word. Ah, and I'm just gonna put typing Jack here. You can putting your name with every Fred, Bob, Jesse, Um and it should work. Just needs to make sure that it's within the quotes here. And I'm also gonna type in my age, so creative age variable. And I'm going to type in 23. And you should see that you have two variables here, and what we can then do is print eso this Will Anything inside the brackets will get displayed into the console as we displayed Hello. World earlier. So what we're gonna do is we're gonna print user name and now what we should find. Sorry. We call it name. So we're gonna print name. What we should find is if we play, it's displaying the name you entered here, which is what we want. And I'm going to try and adds. So we're going to say Jack is, um and then we're gonna try put in the age here. So what this is gonna do is it's gonna get out very well named Jack, and we're gonna put is after it. So this is in it string here because it's with quotes. If this wasn't in chords, we would get era. As you can see here, it's giving it a Red Online to tell us there is a problem. So I'm gonna put it back in quote. And it's also gonna add the age on the end, which we need to make sure is strength. Because if we play, it will see that it's trying to print age and it's saying, must be a string, not an inter job. And so, essentially, what's happening here is it's not ready nosing this attacks. So we need to turn it into attack so would just put use the command str and then just put age in the brackets. So now V it play. You should find that it's saying Jack is 23 it's not throwing any errors, which is what you want. So now I'm just going to change it so we can import our name every single time. So what we could say his name equals input, and I'm going to do two brackets and I'm going to say, What is your name now? If we hit play, we'll see that the console asking us what our name is, so I could put in Fred, and if I enter, it will then run the rest of the code and print. Fred is 23 so essentially, what this is doing is that setting name equal to what every typing and then it's running the code after it, which is what we want. You could also do the same thing with age so you could put input. What is your age? And this would return in the form of this string, which wouldn't be an issue here. But if we wanted to produce any mass with it, we would want it to be an inter job. So to fix that, what we would do is put evil outside of input. So essentially, what's happening here is age is being set, too. Uh, what you type in and then that's been converted from a string into a integer using evaluate . So now forget play you say Ask us for our name. I need to be clicked on the console here. So if we talked in Fred and we put in what your age 23 it tends as Fred is 23 which is what we want. Eso that's the basics off variables for now, and we will delve into a bit more next lesson. 5. Problem #1: Hello, everyone. And welcome back. So this is Ah, a bit of a different video, and what I'm going to do is throughout this course, there will be problems that you can try an attempt. Um, and they will use three concepts that we've talked about for the past for the previous video. Um, and this is just a way of getting you to kind of rein force what you know and what I've just said, because sometimes trying all this information that you you miss a few of the things. So these are too short, quick problems that you can spend 10 minutes on, uh, of it longer if you need to. And just see where you're at on what you need to do. So that's the 1st 1 Ah, and these will be dispersed throughout. As I said, eso this first problem. Um, given the overview, it's called full names. It's nice starting 10 you have to do is in your python program that you write. You must ask the user individually. First name, middle name and last name. So you have to have three separate input statement, um, so that they would trapping like jack for the first line and then the middle name and then their last name, whatever that may be. And they can type. They should be out of typing them any different things. And once they've entered all this, it should output there at full name. So using that string manipulation, we talked about earlier eso examples. It's just some examples of how your coach would work and what it should output with eso. It should ask you, What's your first name? You should be out of type in Marie. That should ask you What is your middle name? You should be out of typing the middle name and at what its last name should be. Added topping last name. And then it should out. Put it in this format search. It's a your full name is at plus the full name that you imported and a full stop of the end . Another example. Here's way. Input Elizabeth Mary Brown. And it prints out your full name is Elizabeth Mary Brown. So, uh, afraid of this, pause it Here. Lookie videos. Um, I'm going to, uh, go onto the solution for this problem. Eso pause the video now, Um, as I'm just going to move on to it, Uh, in a minute. Okay. So ah, all of the's solutions for these problems will be in one place, so you don't need to keep constantly typing in these girls toe. See my solution. You fear bits stuck simply. Just go to this one, and I'll explain what that takes you to in a second. Okay, so now that you've entered that you are Ellen, it should use Hagee to my rappel page. I will talk a bit about this later on in the course, but essentially, this is just day online, like programming I d that you can use. It's nice and simple, and it's a great way to share code with other people. Uh, if you know, in two sites, like, get help. So the way this works, I'll just give a quick overview is you can see all the different files. Obviously, there's 10 problems here. I will add more as I extend this course. Ah, and you can see this main dupuy. So in here, all this does. Is it just when you hit run which runs this code, it will just ask you What's the problem number you'd like to run the solution for and it just runs that relevant file that it needs to eso That's all this code does. Don't worry about it too much, but to view the problem solution or you have to do is just click on a problem one, for example. And this is my solution here, So just zoom in a bit. Here s so it's a bit bigger. And essentially, what this is doing is London. So we're setting available first, equal to an input with the question in it is what is your first name? Remember, this needs to be a string. Eso has quotes around it and for for many purposes, I need to make sure you put a space after questions. Otherwise, you'll have it typing, like without a space in between the question and the input and it just doesn't look very nice. I'll show you what I mean. There are fathers get real that's based there. And I will try to run it like what problem might like to run problem one that you see that when I'm typing here. If I put my first name in this year, there isn't a space in between the question mark. And yet eso that's all that's doing there is just making it a bit nicely for men. And you find that throughout the questions, that's something you just need to keep in mind. So I am just repeating this with different variables. So we got middle, we got last end. Theis line five. What it's doing is we're creating a new variable court full name and as we're setting it equal to first value, which is what they imported plus a space because we will it to print nicely plus middle value, which is what they in put it in the second line, plus in of the space, plus the last names value. So this is just using our variables that we talked about before, and we're using our print statement to display it to the console. Ah, and what you're saying your full name is plus a space here, Um, And then we're inserting the full name variable that we just made on the previous line, plus a full stop. So if we were to run this now, I would say I would run problem number one I take My first name is Jack. Um, my middle name could Bay involved. Doesn't really matter that my last night could be Fred. That doesn't make sense. They go. Your full name is Chuck, Bob Fred, which is what we want to see with this problem. So if you didn't get that, don't worry. Um is a bit of a learning curve with programming, but otherwise, that's if you remember, your code doesn't have to be identical to mine. You could have done it in different way. There's lots of different ways to approach these solutions, particularly with them. A lot of the hard ones, Aziz. Long as it gets the end result, that doesn't really matter how you did it, so you can move on to the next absolutely. 6. Lists: okay, And this ever So we'll be covering your lists so this can contain any type of variable, and they can contain its many variables. As you wish. For example, Ah, you might have a list for the shopping shopping list, for example, which would contain all the different foods you need to make sure that you buy when you go shopping, a list so used throughout programming because they are very easy to search and modify eso. The way that you would refer to a thing in a list in programming is called an element. So each list has numerous elements and can have as many as you would like. Each of these elements has an index location, which we can use to find it in the list. Imagine it like, ah, position in the list, whether it's at the start or the end in this case, index locations numbers said F b 01234 A. So, for example, the three as an index location with correspond to a number in the list, it would actually correspond Teoh Index. It would correspond to the fourth item in the list because in programming index locations started zero So, for example, you see this list here, the actual first item in it is an index location zero. The second item is in an index location one and the third is the index location to. So you just need to make sure that you remember that otherwise you could encounter some issues. Ah, but otherwise would jump right into punch. Um, and start programming. Okay, now that we've in pie charm, what we're going to do is what is going, Teoh, delete what we've got so far and we'll start again. So initially, what we're gonna do is we're gonna create new list, so to cradle list. What you do is you set your variable name, for example, I'm going to do a variable cord names and I'm gonna set it to be equal to two square brackets. So these square brackets, or what we used to define a list I endless need to be of the same variable types that what each element in them needs to be the same variable type. So, for example, are we kind of have a list with both numbers and text? That's just we can only have two separately. So one just with text and one just with numbers. So what we're going to do is we can initially set names to be equal to have some elements. We can just do the quotes inside of it. And we could do John, and we could then do a comma to add a second name to the list. So what we could do now is say, Jack. So we have Jon and Jack in our list here and now. What we can do is we could say print and we could just ask it to print names or in this case, our list. And if we run this, what we should say is that it's just printing John in Jack. Now, um, this is very simple, but what we can do is add items to analyst using append. So what we would say is names dot append and then inside these brackets, here we will. We could say something on the line off ikan. So if we play now, what we'll find is that we're printing a list with John, Jack and Ethan in it. So upend basically adds whatever we've put into, uh, list and put it at the back. What we could also say is names dot insert? Um, we could insert Jessica to be it Index location zero. Sorry, I've got this around the wrong way. It should be zero dash Jessica now for your play. What we should see is that it's actually putting this element Jessica at index location zero or in this case, at the front, and it's putting it when we print it. We can see this because Jessica is now the front. We could change this to be one, for example, and we would say that it would get put in between Jon and Jack. So this is extremely useful in later scenarios when programming So we have upend, which adds to the back of a list insert, which allows us to set it equal to a specific insert at an index location. So I'm gonna introduce you to comments quickly, which, if you use hashtag um, for comment in Python, the this is different in different languages. But essentially what a comment is. Is it just for humans to understand their code? And when Python is reading it, if it sees a hashtag, it just won't do anything with that line so I can write whatever I want in this line, and Python would be okay with it. As you see over here play. There's no errors. So just for comment to help you guys see append ads and element to the back of a list and insert, Uh, that's an element in the specific position you want, removing the others out of it now. This last bit is really important. So it moves the other element that was in the way to like to another position. Because if we were to say names, for example, one which in this case would be Jack is equal to, uh, what is right? Nothing. Ah, what this is doing is essentially finding the getting list. Oh, how terrible. And it's finding index location one. So in this case, it would be John when it's printed, and it's setting a quit and nothing. What you find is that it's now John is no longer in the list, sir. Essentially, um, directly Setting a index location in a list removes what was there previously, which you may or may not want to do. Eso This is quiet. Important to know the difference when insert and setting an index location directly. Now there is one mawr function we would like. I'd like to take you, which is Pop allows you to remove and item from the list so he could say names Pop. And we could say We're going to remove the thing at index era. So in this case, it would be Jessica. We're removing and you'll see that Jessica is no longer in the list, sir. Pop, just lousy. Remove specific item in an index location from analyst eso. You need to make sure as I'm gonna demonstrate now if we were to try and go. Names don't upend and we added a number to it. So 23.45 for example. We would try and play it, and it's actually going to let us because it's Python. But this is a bad practice to get into and will cause issues later on. So it's good to try and keep your lists to specific variable types so that you don't get any issues later on by. You see, the 23.5 was added to the end as expected, but as um, programming, there's lots of specifications, rules and formats that developers like to follow, and one of those is keeping your list to be just one dot type. It also is a healthy practice to ensure that your not encountering issues later run. So, for example, I just sent you a bit of a task on I'm gonna ask you to create available called second name . Um and I'm going to send mind to none at the moment. I want you to try and positively, or he quickly and I want you to set this variable second name are equal to the seconds name in the list if you can figure out how to do that. Otherwise, I'll tell you in a second, and then you can just print second name. So just pause it here on and try and ever think about how you do it on, and then I'll teach you in a second. All right. If you haven't paused yet, make sure you do so quickly. Essentially, what you're going to do is instead of setting it to none. What we're gonna say is second name equals names and we want the first index location eso again this because list on a zero eso the second name in the list would actually be the first name on the list would actually be indexed location zero and so forth. The 2nd 1 is that one. So you just need to really kind of understand how that's working now for hit play, you'll see that it's second name is Jack, and if we were to print the list above it, so if we were to print names, we would find that Jack is indeed the second name in the list. So saying, first name, second name, third name, but it's actually index location one. So that's, ah, manipulating lists, which we will do a fair bit more off later on. Uh, but if just some other simple, uh, commands that you can do is if we wanted to get the amount of things unless we could say amounts off names is equal to Len, which shortened for length, and we could just pass in names here. And if we were to print of the amount of names, we would see that it would be equal to three here. So again, um, that's just another helpful command that we will be using. Sir Len is short for length and gets the amounts off elements in the list. So yet those are some helpful things for the list manipulation that you'll learn these over time, so we'll continue in the next episode. 7. Condition Statements: Okay, guys. So now we're gonna be learning about Boolean operators. So these are essentially true or false. This is a new kind of data type which we will use very frequently. Eso, for example. Uh, just to show you the basic thing, if we set our variable X equal to one and we printed one X equals one and hit play, and it prints true. So what happens here is we can use these operators thes conditional operators at to determine things for us. So we could say something along lines of X is not equal to one and or print false. So this is really useful for checking variables values. We could say something along the lines of X is less. Sorry X is less than one. No, it's not because one is not less than one is x less than or equal to one and so forth. True. Yes, it is because one is less than or equal to one. So, um, these difference condition als wu definitely be used. And the way we used this, uh, is in if statement. So, for example, if we had at name equal to John and age equals, uh, 10 what we could say is if and then a space name. Now in its statements and Boolean operators, we have to use double equals to check if something's equal to something. A friend name is equal to John, and then what we could do is do a We have to do a ah colon at the end of every if statement and hit. Enter now. This should automatically in dent your code for you. If it isn't, you will have issues. So essentially the way this works is we could well print something like Welcome, John. And what this is doing is it's checking. If the name is equal, John will print welcome John sorts, running everything that's indented one layer. And we intend this by pressing tap. And if it's indented any further, we weren't run. So we need to make sure there's indented properly, and this will be where a lot of errors coming. So if we bring this will say it says, Welcome John. Whereas if we changed the name to Jack, for example, we won't get welcome John be printed, so I'll just change that back And what we can now say what we can also do eyes say if names equal John and so weaken Type it out manually. I e n d uh, age is equal to 10 and hit play. As you can see, this now checks to see the ages Eagle 10 as well as name being equal to John. Ah, and what we can do in conduction with this if statement is, say, uh, if ah name equals Joan or name equals Rick, we could prince ah, love them, you amazing people. So or is another key word we can use. So, for example, if we play now, we'll say it prints Welcome you amazing people. But if we also changed this to Rick, for example, we would say it still says, Welcome, you amazing people. But it doesn't say Welcome, John, because it's not feeling this first if statement And just to clarify the indentation here, I went back to the regular no indentation to ensure that this was running all the time. And not only if this state moved workings of for example, if I invented this, this condition would only run if this one was true. And I'll show you what I mean by that. If I change the name to John. It will run both of those. But if I change it to Rick, it's not actually gonna run this second f statement because it needs the 1st 2 run first. That's why I'm I'm gonna leave that un indented so we don't get any issues there. And now you can see Yeah, OK, which I gave the names of John or Rick and this could get really long. So I can do is list. So we could say, um, name equals reeks of is the person that's getting in. But we could also say aloud names M could do a list so we could say John, Joe and Jack And instead we could instead of saying if name sick of this ornate sickle to this musical. This we could say if name him, I would say in allowed names. And then it would print that message. Nosy. And there's no printing. It was. Her name's currently Rick, but if we change it to something like Joe, we'll say that it prints Welcome your amazing people because it's in this list here. So in is another key word that Python allows you use to check if something's in another list. What you can also do is use else statements. So essentially, what this does is you have to make sure it's the same in debt level as a statement and even type else. And you could do another Colin here and you could say Print, go away. And if you run this and we changed the name to be written, you see that it's printing go away because of what's happening years, this first condition in running, because it's not true. And instead it's gonna run this one. The Golway won't get displayed if the first bit is running. So it's a either or scenario and else only runs if the first thing isn't true, saying that what you can also do is Elliff. So essentially, this is like an else if and you can add enough condition, you so you could say if name is equal to Rick, for example Ah, we could then do another colon. We could say print. Yeah, okay. You're all right. And you could save play here says Yeah, okay. You're all right. But it doesn't say the girl way either, because this condition is satisfied. So they essentially if statements will go through a check. And if it's true, then all run what's inside and work around anything else. And otherwise, it'll just keep making its way down the else of statements. And you can chain Elf else of statements so I could add another else of statement here that says, If names equal to ah Abbey and it would do a similar thing, I would just keep going down and checking those things. So that's how if Anel if and else statements were you can also use the is operator. So what we could do is if I got rid of this quickly, I could say if we had X equal to 123 and why equal to a list of 1234 and I printed X equals y. So this would check whether exes Eagle why and tell me whether it is. And you'd say that it's equally false because obviously the values aren't the same. But what could say something like print? Exe is why, and if we play, we'll see that we get false again. So the difference between these is unlike the double equal is does not match the values of variables but the instances of themselves. So if I got rid of the four here and said it them so that they're identical and we get play now, you'll see that the 1st 1 gives true because the values of the same but the second monk is false because they are different variables on and therefore the is operator treats them differently. So, for example, uh, if I did something like if two is two on, we hit play, we'll see that is true. But what this is doing is this With the previous example, you can tell the difference between the two variables and check that they are to actually different things, despite them all containing the same information that could be helpful if you need to use that sort of thing on The last operator is the not operator. So when you say is, uh, print ah X, what would say print to is not to and what you will see here is that this prince false because really, without the not imprints true and not just in verses it, so this will then make it instead of thing. True, it'll say, false on. We could say print not false engaged. You ever want to do it that way? They'll print true and the same thing for print. Not true. Would print faults. Eso That's just another key word that python accepts on and we'll let you use. So, for example, if statements you will use them for lots of different selections, so you could say it. We could have variable here. We could say password. A quartz, uh, input want is the password. And this will allow users to set password to whatever they think it is. And we could say something like, if password equals double equals. Sorry equals 1 to 3 because it's a string. Remember, input is always a strength because we're not using evaluate. If passed was it Could wanted Trey Print. Welcome. You got the password? Correct. And then we could say something like else or otherwise. Prince. Sorry. You got the password. Really? Now, if we play well, see that we can. It asks us for the password and we could say something like 5678 And it says, Sorry, you got the password. Rome. Because it's not equal to 123 But if we did type in one sitting on the console here. We did type in. 123 says welcome. You go the password. Correct. So this is a brief example of how if statements could be used and they are very, very powerful. 8. Problem #2: cloven and welcome back to the second problem. Eso will just get straight into it this time. So this problems called many matters way. The way it's gonna work is ah, you'll write a program that tells you if you have a particular food on the menu um, and this, uh, this line of code you can copy into your program, Um, essentially, where to Setting a list. So it's gonna be available. Good menu. And it's equal to this list here as you're gonna use this list in your programs that eso using this list, you need to be able Teoh, get an import from user, they will be out a type of food, and you need to print out if that food is on the menu or not. Eso some examples of this Ah, here we, you will first ask, Do we serve on and then the usual type in food? So, for example, here is passed up And then because Pastor is on the previous menu, we can see it in this list Here, um, it prints Yes, we serve. Ah e. Another example here is if they typing tacos because talkers is no on this list you will print. Sorry. No, on the menu. Now, some things to keep in mind is we are gonna be case sensitive now. And or so your program should check for the exact name. So, for example, soup and a piece soup are not the same. You see, when they type in, supersize starts on the menu a bit inthe e menu lists we've been given It has pea soup, but those two things are considered to be different because they use a different letters and spaces, that kind of thing, even though too long person there. Probably pretty similar anyway. So, uhm, I'm going to show the solution in minutes. So just pause a video Now our end, we will go straight onto the solution. Okay. Um so of all the solutions as previously discussed available at this link eso you can just type that straight in, and it will take you right to this repel page, uh, which I talked about in the first problem. And we can navigate to the problem to dupuy solution. And I walk you through how this works. It's a pretty Oh, sorry for me. It's renamed at the wrong thing for me. it's problem. Three. I'll fix it up and it won't be, but go to problem. Too few, uh, and you'll see that we have the menu. Ah, lot of card that we I copied from that slide. Eso you can just copy that yourself on. That's just creating a list and sending an equal to a list with these elements in its has passed a bull in a pesto piece. Suits make seven mushroom pied green curry fried tofu. And then we're just setting this variable food equal to whatever the years types in when we asked to be served, remembering to put that space after the question at just sort for months, probably. And then we have a simple if statement that says, If food in menu on and then we can just print, uh, either yes or no, depending on whether that food is in the menu. So in the case that it is in this list called Menu, that will print Yes, we serve that otherwise will prints. Sorry, no, on the menu, so it's, um, only a few lines of code. But essentially, it's just using this in keyword, which checks if an item is in a list, which is Ah, many was list here and food is the item we had checking against. Ah, and this returns either true or false. Boolean variable times. Ah, and of course, his statements need to check if something is true or false in and then run the code accordingly. Surface trade or run 95 Otherwise you'll run at line 17 eso. Hopefully you got this problem and you can move on to the next video. 9. Problem #3: a given. So we'll jump into this third cutting problem and this one is going to be called ballgames . As so now, we've just talked about if statements were going to use them. Eso this program is going to ask the user what board game they're gonna play next. Um, and if they're going to play ball game, Kurt names, we'll tell them that it is a great game otherwise will respond with. I will set up the ward So it is using those if l f and l statements at like we want eso Pretty simple eso examples. So is we asked the question. What should we play next? If the user types and code names will print awesome l of code names and we'll print, I will set up the board. Otherwise, if user imports anything else such as settlers of Catan, we won't print that Awesome. I love code names and we'll just print I will set up the board Eso it's, um simple program. Ah, and you can have a crack at writing that now on and pause the video. Aziz, I'm going to move on to the solution so as discussed before making head to this you, Earl, to view the solutions. Oh, and run them. So I'm just gonna head over toothy repel Ah, and head on to a problem. Three eso. The way I have done it is I've set this variable game equal to the import of user. When we asked the question What you replay next remembering that space at the end there for formatting. I ended line to just use that if statements. So if game, which is what they imported, is equal to code names. Now remember, we're having to use these double equals inside of any of statement. If we use one equals, it would give us an error on, say, invalid Syntex. We don't want that. We need to use double equals. And we're saying, if it's eagle to the string, we've just hard coded to be code names. Ah, and if that's the case will print or some I love code names because we want a print. I will set up the border every time, no matter one that that isn't inside the if statement or if we, um, didn't want to print that when they said Cornyn's would use an else time and big currently with the way the question is worded, we will just see that That's no indented. So we'll get run no matter what, which is what we want and we want to run after we print also my love code names. That's why it's below it. As so. If we would run this now and we would to enter problem three, I would ask us what we play next. If I typed in code names, that would say Awesome. I love co names. I will set up the board, which is exactly what we want and if I would ah type problems right here and I would a typing settlers off Ketan, I will say that it doesn't print their awesome I love code names eso that's that problem and you can move on to the next year now 10. Mathematical Operations: Hello, everyone. And welcome back to this lesson. And today we're gonna be looking at maths and different atthe manic operators you can use to add, subtract, multiply your variables ends as such. The first thing we're going to do is just the different symbols that python users. Some just gonna write them out here on comments. So first is the plus adds quite self explanatory. And the minus minus is s O, for example, if we said Prince one plus one, you'd see that it prints too as and if you were to print one minus one, you'd say that it prints zero. So, uh, the next few more complicated ones Ah, multiplication, Which is the asterisk. Um, so that's just a new one. You have to get used to most different languages. Use that, um, as standard. So just remembering that you'll eventually learn. That's what that stands for. And then the bank slash is also division. So if we were to say print eight divided by two, you'd see that we get, uh, press room. But if you'd say that we get full because it is a division, this will return afloat as well. That's just something to remember because technically, you're never precise enough to get for it for the whole, um and you would need to make sure that you just use, evaluate or round to make sure to get a whole number as a result of division. You could also do something similar to eight times for and you should get eight, as you see here. So that's the four basic operators. If you were to do something like a print one plus two times three at divided by four point . Oh, uh, python does follow the order of operations, so it will do things like division multiplication first and then addition of subtraction afterwards. So if we really hit play, he should say we get 2.5 because it does follow the order of operations. Uh, the next, uh, Earth medical Breda we're gonna deal with is the modular or percent sign. Essentially, what this does is it gets the remainder eso If we were to the remainder, if we would do our variable, remainder equals 11 percent three. Ah, What you should say is that it prints the proper remainder. Um, as such from 11 divided by three. What's left over so 11 divided by three. Normally, I would do it up to nine, and then you have 10 and 11 left over. So you get to That's useful for, um, later down the track when you're doing a bit more data science stuff, which we don't cover too much in this course. But if you do see that, that's what that symbol does mean. Ah, and you may use it occasionally. The next operator is to estrus, which is a pal. So if we were to say, um, this square off seven is seven and then to Astra's to, you should see that that squared to seven squared on that prince 49 as expected. Um, so there, that's what the two estrus mean is power. Um, and you could also do seven cute. But what's Seven Cube, for example? That would be seven asterisk Astros three, and you get 343 which is what's expected. You can also use addition when combining strings, for example, we could print ah, I and then we could at a plus in between it and to, uh, I am amazing. So what you see is if we hit play, you'll see that it's added both those strings together. Eso plus can add variables off the same data type together. If, for example, we tried to do three here, we would get an error. We would first need to convert it into a strength and then we would find that it doesn't give us an error anymore. Also says three AM amazing, which doesn't make sense, but it is working. Have expected. It also supports multiplying strings. For example, if we had a variable court, lots of hellos, we could say hello and then what we could do is times it by 10. And if we were to print lots of hellos, we would see that it. Actually, it's short displays. Hello, 10 times. Ah, so this is really important to differentiate your data types here as well. For example, if I was to make sure this was printing a string version of this variable and set this variable equal to 30 that would do 30 times 10 which will be 300. But if I would have put 30 in quotation marks, we would see that it actually just prints 30 10 times. So this is really important to notice the differences between those two things so that you could look out for them. We can also on list together s O, for example, if I had a vegetables list which has, like, a broccoli broccoli, um, I need make sure it's a list of, well, so square brackets, Uh, and then we get tomato, cucumber and close up list. And then we had a fruits list which had, like apples, uh, and then mangoes and oranges. We can see that if we wanted to print, say, a whole shopping list with vegetables and fruits together we could do vegetal print vegetables plus fruits, and it would print a list with all of those together. Obviously, vegetables would all be in front of fruits because of the way I have structured this, Um, you can see that it is displaying the vegetables first because it's adding the first list and then the second list at the end off it, you can't do anything like dividing them because you get errors because you can't divide ah , strings killer. But you could if a list were off type in the job, you could divide them like that. Another thing you can do is multiply lists by numbers as well. So we had out numb lists, which is just eagle toe list off to, say, 145 and we tried to print number list times three. You'll see that it actually prince the list three times, even though they are of type into job, because it's a list. It's not reflecting that, but just to make sure it's always good. If these were in quotation marks s so that you don't have to worry about any issues encountering with errors, but you can say it's does the same thing. These watches have quotation marks, but yes, you can times lists by numbers as well. So that's the basic arithmetic operators in Python. You will learn and use those throughout the course and programming eso. It's good to learn what those different symbols mean and the ways you can use thumb in python 11. String Formatting: Okay, so now we're gonna between that string formatting. Usually I prefer to use the addition or plus symbols to add strings. But you can also use other string formatting requirements. For example, if we had a variable cord name, which was a call to John and we wanted to print Hello, John, normally I could would do something similar to this, And it would be hello. Plus the name, which would print Hello, John. But other alternatives This would be using the sea style formatting with special symbols, which is the present symbol that's appointed Hello on. And then I did the percent symbol and did s because it's a string. Uh and then I, after the prince statement, did another percent symbol to signify that we're using the string formatting and I need a pass in the variables. I'll explain how this work in a second, but you see this plane prints Hello, John. So, essentially, what's happening is we're asking the prince tainment two prints, what's inside here, and replace anything with the percent symbol in front of it with the variables we passed in . So, for example, if we had aged equals 20 three and we did. Ah, percents, Yes is percent day years old. And then we passed in name and then to the Komar and did age. And we need to make sure that these to set the variables were passing are in brackets. Otherwise we'll get ours. I will say this does. John is 23 years old, so essentially, what's happening? Here he is. It's replacing. Sent s with the first variable that appears, and the S is indicating with his strength, which it is. And here the second, where war is being replaced with age on because it says Dave, because it's an indie job. Now this is pretty counter and charity. If that's why I don't like to use it as much. But percent days into job percent. Evers float. Ah, and you can do percent dot and then the number of digits for afloat as well, which will round it up for you. Better sense. But like really, what it's doing is it's just replacing the sections in the string with the variables values . So it's just a different way of doing it. So we could do something with the list is well, we could say my list equals 123 And we could just say print percent. Yes, and just pass in my list here. So what? This what we could say list and we hit. Play now will say that it just prints the list regularly. Uh, because we've used the string formatting, whereas if we did percent day, uh, it would give us an era because it can't prints a list in the form of a number. So that's why you need these percent s there. Because percent, as signifies, string, the seventies indigent percent f is float just to sort of float. We could do my float because 1.2 and we could say they float of course, percent of and then modular Well, the percent operator and then passing my float, and we'll say that would not getting an issue there. You see, it's a rounded to lots of different decimal places. Um, to stop that we could, for example, due to f which would do it too, to what should do it. Sorry if we've got the percent dot two f, which would do it to two decimal places, as you can see here, which makes it a bit more consistent So, for example, if we had two variables and we caught one daughter and it's equal to a triple now, a true pool is essentially a list but allows a difference variable types to be inside it. So I imagine this to be like a list, but not entirely. Um, because you can't use all the at least methods and index locations on it. It's really a bare bones list. That's a lot fast for the computer to run because it doesn't have all of those extra attachments to it. So if in this list we had 23 variables John Doe and we had a 53.44 and we had the string we wanted to former Ah, well, if we wanted to print, uh, the amounts of the person's name, plus the amount of money they have in this case it was 53.44 What we would need to do is you can have a golden if you pause it. Uh, if your prince Ayman looked like this, imagine that just being subbed into here, you would just say something along lines of hello and then you do percent s space percent s and then maybe a full stop. Your bank balance is and then we would do percent. Don't to F because we want it to be to two decimal places and it's afloat because it's a decimal number and we hit. Play now issued today says Hello, John Doe. Your bank balance is 53.44 If we wanted to dollars in Bloom from that, we could put it there and you'll see that it appears properly. So it's just another way of manipulating strings. It's after personal preference. How you'd like to do it this way is makes a lot Tidier, but I find it's just easier personally if I use the addition. 12. Problem #4: again front. So moving on to problem for now, this one is going to be using our string manipulation and maths operators that we've just talked about. So this problem is called Happy faces s Oh, well, it is is you're gonna write a program that they ask the user how happy they are on a scale of one to infinity. Uh, end responds with a happy face to match that match. How happy they are. And what do I mean by that? Well, the examples kind of explaining, So we'll ask the user how happy. And they will give us a number between the one and infinity. So, for example, this one prince one on and it will print a happy face with just one underscore. Whereas if they entered four, for example, you can see that it prints four. Separate underscores. That might be hard to see, but that's kind of the basis of how it's gonna work. So remember, we can multiply strings, but numbers too make them repeat multiple times as we talked about before. So if you want to give that a go, you can pause the video now a za I'm going to move on to the solution and explain how that works in a bit more detail. Okay, so, uh, the solution again just had to this euro. Um, it's the same for all of the solutions. So you only have trapped him once on, and it will take you to this repel page. Ah, and we will go down to problem number four. So it's just a three line solution that I made. Obviously, if you was different as long as it works properly, that's what we want to see. Eso The first line is again just getting the input from the user. So I just called by available amount. And no, I've had to do some data type manipulation here with int. But what it's doing inside of this is getting the input from the user. Ask them how happy it is end now because I wanted to be a number. I am using this int prefab with this insight method with the brackets around the input statement. So this would be identical to using s if I created available, could import and said it equal to this, which just asked the use of the question. What amount is doing is it's just turning the string input into a number now. The reason I'm using internal evil is because I know it has to be a whole number. Um, and you can't have 3.75 Smiley faces doesn't work like that. Eso That's why I'm using an integer. Obviously, you would do every taking the safe. They did enter something that wasn't a number, but we haven't gotten into that yet, so we're just gonna assume there's always a number and it's a whole number. Eso that setting amount to what we import it as a number on. Remember, this will be giving me issues if it's non number. If it is, if you're trying to multiply it by a string, you'll be getting some errors of some kind. Eso definitely needs to be a number, and we're setting this variable smile eagle to underscore times the amount so this would just repeat it. So, for example, of his times by one, it will just return. One underscores it sounds by 22 underscores and so forth. And then we're just printing to the I plus thes smile, which is the amount underscores that we've determining its fair ball plus the other eye, and it's if we would have run it now. And what a typing problem before we would see that if I type in how happy and I did 100 we'd get have very long smiley face. That doesn't really look like a smiley face anymore, so that's the basis of that solution to this problem. 13. String Operations: Hello. Run. So now we're going to be dealing with basic string operations. So, uh, what I mean by this is just a few different ways. We can just tell strings and different functions on methods we can use with them. So, for example, if we had our variable, just call it a string and it's equal to hello world. Now what we could say is we could use our Len function, which is short for length, and we could pass in a string. What this would do is it will count how many different letters or characters are in the strings, for example, that the there are 12 in this. So 123456789 10 11 12 does count spaces as characters. So just be aware of that. Ah, and this leads into an interesting, um, another feature, which is counting how many of how many times a letter of peers in a or a string. So, for example, I could say a string don't count. And I could say, OK, how many times does l appear? And if I run this, it would hopefully tell me three times, as you can see here. So what you do is you did very well name to this. Could be my They're my viable that my variable and you have to do dot count. So this only works on strings which remember our words and letters. We could do the same thing for oh, here, and it would return to because there's two O's in the strength. Other things we can do is using index locations. So imagine a So this was a list we could say. Um, remember our list with index locations and elements? We could say I want the index location off. Say the hatch. And if I hit play here, it would tell me it's an index location. Zero. So imagine these to be like a list which has or split up. The string is a hole into lots of different letters. So it would essentially look something similar to this eso. If that helps you visualize it, and then you would have to say the space and so forth. And then you have worked in the exclamation mark. So what this allows you to do is get certain sections or portions off the actual, um, string using square brackets. So using the square brackets allows us to get sections off a list. So we could say, OK, I want characters. Three colon to seven. So this means I won't characters 3 to 7. So in this case, it would be at this l through 2456 to the O. I believe if I kind of that right eso yes, it's grabbed this one, these four characters it has grabbed. So you can see it's got going from index location to Ray, which, actually, because it starts from zero is the fourth letter through the eighth letter, which is in index location seven. So this allows you to get a different section of the list. So, for example, if I wanted just the world part, I believe that would be right. Or is this going to mean era there? Yes, it grabs the world section off the list. If I do 6 to 12 you can see it gets the end section of the list. So that gets the world section. Another way to do that would be the use negative numbers. So I could, for instance, I want negative seven through to negative one. Now if I hit play, we should see that it displays world the exact same. So what is this doing? This is grabbing the section from negative seven so imagined that the list starts here where my cursor is and it's going back around. So this would be exclamation mark would be negative. One negative to negative three and so forth where the space here is negative. Seven. And we want to grab everything to right of that up into a native one, which is the exclamation month. And you see here that it is doing that. What you can also do is grab different characters or so what? I could show you an example of this. I could do three Colin seven cotton to So what this is doing is it's starting an index three and ending it in next six. But it's not seven, so I'll show you what this means. So what this is doing is essentially, it's in this former. The way the square records work is you have the start location and then you have the stock location begin. Also have the step location. So the way this step one works is it means how far h time it grabs the letter. Will it move to awards East Op location? So, for example, what it's doing here, it's probably easier if I change the string a little bit. Eso that there's no space that's you can say it a bit easier, but you say it's grabbing the L in the W. Because what it's doing is it's starting it index location three, which is the cell here got hollowed, and then it's jumping to across to the right towards this index location of seven. So it's essentially skipping the O and going straight to the W. And then it actually can't get this other zero because, um, it's no within that one. It would require one step, so I'll show you what I mean, if I put one here, this actually acts like a regular, um, slice. But the two means that it's jumping and can't. It skips over, sort skips over the 1st 0 and then it skips over the second only for to continue its keep over the L and then the exclamation mark. So that's the more expanded syntax with the step included. If you want to use it like that, what you can also do is You don't even need to stop location. So I could do, um three. Kahlan. And what would this would do is it will get everything from index location three onwards. So this would print Low World, as you can see down here, Um, and you could do the same thing backwards. So I could say what? Everything up until index location three. And it would print health and so forth. You could also do everything up until, like, index location Negative five. If you wanted to use the negative versions off that. So that's the list string manipulation part off it. What you can also do is use the dot upper and dot lower methods so I could do at my variable up, up, and this will convert all to upper case. So you say it says hello world calling capitals and I could also do the dot law and you would say a similar thing with being all in lower case. So this is very helpful with, um uh comparing things without if statements to check. So, for example, if someone accidentally typed in, uh, upper case for a letter, you can always check against lower case to stop that happening. You could also do something similar using the starts with eso What you do here's you'd use my variable dot starts with Michael part in something like Hello. And if we play this, it will return true, cause this checks okay, is a start part of the very walk saying hello for exemplified changes to say world here, it doesn't actually say world of the start, so it would print false. You can also use the ends with on this was still print false because it doesn't have the exclamation mark that it needs to check that. So they go and it prints. True, when I had that exclamation mark So that's, um, those string manipulation. There's one more, which is the dot split. So essentially, what this does is it for turning your strings into lists. Eso you can choose a character to split string into list segments, for example, this is splitting up by the space here, so it will essentially turn into a parable which the list that has hello in one section and world in the other. It also removed the character that is split by so in this case, the space so you see if we print it now it's in the form of a list, a ser that's extremely helpful. For example, if you wanted to passing a lot of arguments for starting a program, for example, So if I had maybe, um, if I used to say this straight line operator or this divider to split it by, I could then pass in ah whole bunch of different values so I could say, like t 60 and then like s a door. And then why do whatever you want? And then it would split it have by that's operated there and maybe piece. It's just easier way than sending list cause sometimes when you're sending messages safe through the Internet, it's better to condense them into one string rather than less. Because not all different languages support the way python structures lists. So turning him into just a string or languages will support that. So that does the basic string manipulation, functions and methods that you need to know. Um, and we will continue on in the next episode 14. Problem #5: I gave him. So moving on to problem number five, this one's going to be about out slicing and converting strings to lists and that kind of thing. So the way about this problem involves riding a program to check if a thistle is front. But if a string ends with ing so we're gonna ask the user for an import, they'll put in a word, and we will check if that word ends with in N. If it does, we're going to remove that i n g off the end of it and then wages going to print that. So it should just do these. Follow these steps, and I'm one check of the word ends in I N G. If it does remove the Angie from the end of the word. If it doesn't just don't run Step two and then just print out the word. So if it doesn't have i n g on the end of it, then we'll just print the word as it usually as it was inputted. Seven Example like this is if we input science doesn't have NGO me, and so we'll just print science. Whereas if we import climbing, it will return a climb because it's gotten rid of the i N G at the end of that strength. Eso some things to note is you should remove i e g even if it doesn't make a real word. So bring it's just br But that's the way we want this program to work. Eso using that slicing in if statements and that kind of thing to give you an idea of how to do this. Ah, you go program that now. And I am going to show the solution, uh, in a second. So just pause the video, right? Your program, and then you can import it. Okay, so now I'm going to move on to the solution. I hope you have posed a video. You can go to these girl like all the previous ones to see the suspicions on. And I'm just gonna open that now. I believe this was problem number five. So I'm just going to select that. By the way, if you're fast aren't showing, just click this files, but in here it will make it appear so thesis ones. Just if once you understand the concept, it's quite simple. Eso the first line eyes just getting input here. So we're just getting the word that the user is imported. And now number two, what we're doing here is where settings, verbal and word equal to the last three letters off our, um, word that was imported. So this is using the slices here. And remember, what this does is we can imagine that it's splitting up our word into a list. So I'm just gonna comment this out here, but if we input, I don't know climbing. What would happen is we're essentially changing this into a list which is equal twos, which has allowed the elements. Um c l, uh, much as big word here. I I am Bay I and and, uh G There we go. That's essentially what this is doing here and where trying to grab. Remember our list started. Zero eso the index's locations. Four days will be a 012 3456 and seven Like sewn. Um, and we're trying to get the last three characters. So with python, what you can do is you can use negative numbers. So if I had to put three here, um, this would grab index three and the colon here. So we have this start and then we also have to stop so I could do 36 and that will grab em to end. But because I don't have anything there, it would just grab to the end of the word. So be empty. And what negative three does is it's essentially going okay, I'm going to go to the back of the word and work my way. Fort. So this would actually be location, negative one. This will be negative, too, and this will be negative. Three. And it started this, I hear, and it's told to stop. At the end of the world starts growing negative. It's going ITV another way. You could do this being negative trade, negative one. It's essentially those to negative, afraid to nothing. And Ignace trade negative are identical, and it's crabbing this end of this word here and turning it into, um so if we have, if it was just is turning into a string, that's G. Regan candidates them. But that's the process that this is following here s so hopefully you understand that, and then always simply doing is checking If these last three letters is equally in if we're doing that Wages printing the word all the way up to the last. So, um, if I was to get that back here that way, printing from zero, this is the same. A zero. Um, remembering that. So that's the same miss that *** three and nothing negatory is the same as we're getting from sea all the way up to the negative third number, which is just I, but we're not. But that isn't inclusive. So actually, getting enough from C to B is the way that one is working. So we're going from C to B. It's That's just a simple way to remove the thing off The end of the word, uh, other ways you could do it with beta print from Ah, well, actually, no. That that is the best way to do it. Sorry. In Otherwise, if it isn't in the worldwide is spreading the word again. So ah, if we were to run this now and we were to say OK, I want to go from I wanna run problem five. And I want putting climbing. Uh, it would print climbing the reasoning. That is because I left that negative one in there, um, a flower to put climbing. And now you'd say that it's printing climb. Where is father to put in science, for example, that you would see that dis returned science because there isn't any i n g at the end of that word at so that's the solution to this problem of five. 15. Loops: okay, in this episode, we're gonna be covering loops. So the first type of loop we are going to look into is the four Luper. So this is extremely common, and python simplify that down to make it really simple. Eso this loops allow you to in terrain through lists and different elements. Essentially, they're all in the former off a list. Um, so it allows you to go through each different thing in the list and work with it. So, for example, if we had a list of names and it was a list and we had say, for example, Jack and Joe and Bob and filled, for example at what this would allow us to do is go through each thing in sight like, Okay, is the first day me could, Jack? If so, print. Welcome, Jack. If is, the name equals two. So and then run that same code on every single different part off the list. So I'll show you how that works. So the first thing first has we used the four key would and then we set a variable name or come up with one that would just be equal to the current element we're iterating through, so I'm just going to call it name. Name, which is different from the names are just help. I'm gonna call this one names list just so you can know the difference here and you say Forage name in. And then I will say in names list and then we do it. Colon here, like out be of statements, and I can just say something simple, like print name. So what this is doing is it's looping through h different things that'll look through jackal it through Joel's with Bob. It'll look feel, and it's running the code in here, and it's sending this variable equal to the different element age time it runs ago. So essentially, it's trip aiding the code until it gets to the end of the list. So if we have playing here, you'll see that it's printing the different elements in the list. Jack, job or field as you want. And then what I could do now is in this for Looper could say something like if, uh, name is named outlaw just to insurance in locus is equal to I hope we can save print of his awesome and then we could say else Just print the name. So remember, without indentation here, everything inside this loop needs to be invented once and then close it if statements everything inside of those needs to be indented another time and so forth when you in the bigger virgin get indentations upto like 10 times and it becomes a little bit ridiculous. Um, but you should see here what's gonna happen? Moving it play. It'll say Bob is awesome instead of pretty pulp, because this name variable is equal to each element each time is slipping through. So I hope that's kind of making sense to you. Um, and you can do similar things for four loops, so I can do canning numbers in a simple way of doing that is, I'll say, four and others called local variable number one number, and I'll say in. And instead of doing a list which was equal to us, for example, man 23456 If you wanted to look through all the different numbers, I can just say at range and I can say, uh, 0 to 54 and then to a call in. And I could save print numb and Essentially, what this doing is if we play, it'll print 0 to 3 because this range version is inclusive and exclusive for the second figure. So what that means is that just need it will be one. It'll finish a one less then what? It's so if I wanted to have print out before, I would put five on and so forth. So this range method creates that list. Forests essentially, is what that's doing. Eso that's looping through the different numbers and allows you to go to something like 500 without having to do a massive list, and you can see it's printed or the different numbers up to 500 here. And then I could say, Okay, I only want to print the number if it's if, ah, numb, divided by if the number divided. But if the remainder, when dividing it by two, is equal to zero, I want to print it. So this means only numbers that are only even numbers essentially is what should be printed now, and you'll see only even numbers are because remember, al percent sign is modular, which gets the remainder. So we're saying if when it's divided by two of the remainder is equal to zero. So it's divisible to then we'll print it. So it's and that is like, how you find two even numbers. So the next type of loop there ISS is wild loops. So these work by running until a condition is false. So, for example, I could say, Ah, variable is called end outside, it's false and I'll say while and is not equal to true. So exclamation mark equals means no equal to or I could say not equal to truth if you wanted to do that. But I prefer the not equal to symbols eso while and is not equal to true. So in this case, secret false. Um then it will run everything in here, And I'm just gonna say end is equal to, uh, input. Do you want to end and are these need to actually, uh, b string? Sorry, because we're using an import here. So now, for you play what we should find is it's initially sitting and variable with a false and then this is going to run repeatedly as long as his invariable is not equal to true. So if we say if we just type in anything that isn't true. It will just keep asking us if we want to end until we type in. True. So if I type in true now, I assume in there coming true. And then it ends, which is what we would expect. Um, And then there are other different, uh, things we can do in while loop, such as break and continue statements. Uh, so the way this works is if we had, like, a count, there was accountant secret zero. And in this world statement, Now, don't usually do this unless you have a way to get out of it, cause it will crash your program if you just have a world true loop because it will run forever. Unless you have one of these break things. So if I say can't is equally account plus one or if you want a shorthand that you can say can't plus equals one that will just every time this bronze, it would have had one, too. Can't what I can taste if, uh, count is greater than five. Then we will just break. And I'm just gonna print count just for the fun of it. And I'll explain what this does, You can say it prints one through to six because, um is going to. So essentially, what's happening here counts at 20 This is looping. It's adding one account. It'll be the one. It'll imprint one, and then it will check. Okay, Is one greater than five? If not, then the loop again and keep going all the way up until says Okay. Is five greater than five that No, it's not like 1/6 grade in the five years it is. Then it will exit out of the loop. Ah, that's the way that works. So it's nice and simple, And then there's also continue, which is more better suited for out for loot. So if I say four X in range at 10 which would just remember creator lists of numbers up to 10 and I'm going to say is if X is equal to continue, and I'm just gonna print exe each time here. Okay, so what this is going to do is this Continue statement, um will stop running any other code in the loop and just go to the next generation. So that's why it's not printing to you, because without this if we just had, like, setting a variable or something in here, and it was one and we had play. You see it does print, too, because if statements once they complete, we'll just go to the next line. Um, but because of the work continues, it will stop everything else after it and go to the next iteration of the loop. And same thing is, if I change this to break out one day is, too. It will stop the loop entirely, and you say it's any printing zero and one. So that's, um, the basics for loops. You can also use else statements in while loops. If you wanted to do that, for example, you could say count equals zero while counts. It's less than five and then do it. Collins. A prince can't when it's less than five. And then I'd want each time we could also have an else here and say, um, print count value rached. Oh, I didn't put it since in a string count value rached and then just display the count about you here. Of course, we need to make sure that's a string or else we're getting error. And if we a play. I will say that it's, um, 0 to 4. It's running this code in here. And then when cat is no longer less than five, it's going to run thes Cody A. To this runs basically wants, the loop is over or the condition in it is not true anymore. So that's the basic sloops. Um, for this video. 16. Problem #6: Hi, everyone. Welcome back to problem number six. As if this once simple times tables and using al loops knowledge at this one's gonna giving you a bit of Ian here is gonna be using our four lips remembering our range and that kind of thing that we've used before we just learned about Sorry. So what you need to do is write a program to print out the times tables for a given number that the user just import itself. For example, they put three. I will do one times three to country so on, although after 12 times three s, so it'll just terminated 12 times that number. We're going to assume that the inputs always gonna be a whole number or an interview. So you don't have to worry about any other order or quit numbers. Can you just simply print out multiples? Um, and what they equal so will say, like one times three equals three on each of those should be on a new line. Eso examples of this year's. If we put in three, it'll just print out three times one all the way up to three times 12 with the respective three and 36 being the answers. Same with nine years, but nine times one or that one times 12. Um and that's what this program should do. So obviously asking what number that would like to enter and then doing it accordingly. Assuming that this is gonna be a positive number, Uh, the whole time eso that's what you need to program. Um, and you can pause video here as I'm going to move on to the solution and explain how that works now. Okay. So you can go to this year old to view these solutions and run them yourself. It should open up this repel here, and I'm going to load problem number six eso That way that this one works is quite simple. It's just three lines. Um, and you can see, uh, that way, sitting the number equal to the indigestible, converting it here of what the user imported. Um, And we are using these for loop. Here s O. What we're doing is we're going forward with doing this friend available Count. This could be anything. You won't just make it up as if account in range 1 to 13. Why is this okay? The first number here is inclusive. So that means it will start at one. And the second parameter in this is exclusive, which means wanting to count that once it'll go from 1 to 12 because it isn't counting the 13 here. And then you're simply this printing the number I have just realised I'm using s strings here, which we haven't learned about. But what you It's essentially this is just, um, formatting it. But I would just change it to use contamination eso that you can understand how it works. Ah, so you dio Okay, So the way it works is we're printing the number which was imported, so's to be three or nine in those example cases. So be three times whatever we're up to what iteration were up to in this loop, So three times 13 times to three times three and then we're just doing with it equals end. We're converting the store string, and we're just times in three times one the computers working in our and then we're just printing it by using the string commit eso. That's the way this is working. Um, so another way just to simplify here, you could Ah result equals numb times can't. And all this string doing string, but is doing is just converting it from an intern from a number to a string so it can print it to be doing so the number of times we're just using the X symbol here, plus whatever it aeration were up to. So 1 to 12 ah equals And then the string of the result, which is just timing those two numbers together. Um, so that's the way that this program works and you'll see that if we run at number six and we put in, for example, 100 you'll see that we're getting an era because we're trying to add strings in a, uh um, we're trying numbers together when it expects the strings, So that's my fault. They're obviously not using the right data types, but now I put string around it. If we were to run problem six and entered 100 you'll see that it says 100 times one all the way up to 100 times 12 and it's working properly. And as we would expect, so that's it for this solution to the problem. Uh, and you can move on to the next. Did you 17. Problem #7: I gave run. So this is to problems back to back, because those their first problem used a for, uh, this one is going to try and get you to use a wall. Loops is problem number seven. Eso again referred to that loops video if you're a little bit stuff on what to do. So this is a alarm clock problem, and you are riding a program. That axe is an alarm clock for you on What do I mean by that? Your program should print out, meet me, meet Ah, and ask the user. Are you up yet? And until the user enters, I am up specifically this, um capitalization and pronunciation of it. Um, if they don't enter it, repeat this cycle and keep going. Meat, meat, meat Asking how you what? Repeatedly. Until they are, say I am up, then your program should end. But when it's ending, print took you long enough. Uh, like that. So the examples probably help with this one. Um, for example, So it will print meet Meet me last you Are you up yet? For example, the user here is in footage, and it's then repeatedly going off. I stay up there said I'm up with, um this obviously isn't the string we're looking for. So it's going Meet me. Meet again. Are you? Arbit says I am awake. Obviously, we're not looking for that either. So it repeats me meat meat on, and then they finally say I am up, and then it prints took you long enough and ends. So you gotta be careful for infinite loops on this program. This is what you kind of expect from this problem again. Another one here is going. Event notes Still repeats on sleepy repeats. Snooze repeats news Repeat. Okay, okay, repeats. Then they finally say I am up. Then it prints Took you long enough. That's that's the base. This program, uh, that you need to write. So I'm going to move on to the solution now. Eso pause the video as I'm going to explain it and try and have a crack in it are using those loops that we learned in the previous video. Okay, so now we're gonna move on to the solution, go to this u r l if you don't have it open already on, and we can load up the repel it and go to problem number seven. So it's just five lines. Obviously, if yours different on, it still works. That's perfectly acceptable, sir. The first line. Wejust initializing this variable response and I'm setting. It's nothing, just an empty string I could literally set equal to none, which is a basically none data type. I like stringing it if you want it, but I'm descending into an empty string and we're using this while loops. Remember these. Have a condition on them and milk repeatedly. Kate Running are the code inside this indent until this condition is true? So we're saying, Well, for sponsor is not equal to I am up Baikonur. Apparently print this message meat, meat, meat and then ask them all you want. And if that's the case, um, sorry to store and everything. So it will sit response equity of what they import and if what they input is not equal, I am up will repeat this cycle until they enter. I'm up, and then obviously, once it's equal to that, it will go. It will run, learn five. Imprint took you long enough, so if we would a run problem number seven here, see it says meet me. Meet I up If I, you know or should shut up or if I use any other um, way of saying I'm up. So, for example, that's all lower case there it's still repeats until it until I finally say I am up with that capitalization that says took you long enough like we would expect so again, initializing variable. This is painting until we enter him up. Infinite amount of times and this condition on it is while response is not equal to so that's what T ag exclamation mark plus and equals means not equal to I am up. Then it repeats, and then it will print that at the end. Once it stopped eso, hopefully you didn't have too many infinite lose weight. Your program crashed Tom, and that's it for this problem. 18. Functions: Hello, everyone on. And now we're going to be looking at functions and these are extremely used throughout programming. At an intermediate level, almost every single piece of commercial software will utilize functions. They're extremely useful when reusing and making modular and adaptable code. So what is a function? Well, functions are convenient way to divide your code into useful blocks, allowing us to order it making more readable re user and save time. That is the biggest thing with them. Ah, what I mean by that Ah, you see, when I demonstrate it, Ah, but essentially they allow you to group code together and run it using different parameters or variables. So an example of using functions would bay in a group environment where you're building a website now, one programmer may be responsible for creating the log in function. Ah, and they would initially plan out that this function would return if the true or false, which is representative of whether the person logged in successfully or not. Um and this allows the other programs to begin working on the rest of the website. Even if the Logan system isn't done, because they will create a function that automatically returns true. What's that? Working on it so that when But this is really seamless because when the person doing the log in function is ready, all that have to do is just copy the code into that function, and then it will work for everybody on our kind of. Hopefully that makes sense. But I'll explain it, Maurin Python, and we'll jump into it now. So, um, the way that functions are set out is you first have to define them. So the way we do this in Python is just by typing in death. So this stands for define and we're going to define this function and weaken like variables . We can give it any single name we want. I'm just gonna call it my function, and you need to brackets following this now, inside these brackets, we can have prominence. I'll explain what by our but later, But for now, we're not gonna have any. And then, as usual, we need to follow this by a semicolon and remember, with our semi colons, what that means is that the next lines have to be indented. Ah, and essentially everything in this Indian will get run when we call this function, so we'll just do a simple print message saying something along The lines of functions are awesome. Awesome. Okay. And now how do we run this function? Well, Ah, we have to go out of the UN indent here, and we just simply call my function like so So you called an Emmy function, plus the brackets. So the way this works is you define all your functions up above your main code. So in order to call a function your coordinates, we blow it. For example, if I were to try and call my function from up here, it would give me an error. And as you can see, there red underlines because it's not referenced. So in order to call a function you need but blowing python and as you say, if we run it now, you can see it prints the message. Functions are awesome. So that's the basics of what functions are. You can have multiple functions. You have as many as you want. Ah, so for example, I could do another my other function, and I could do a simple print message saying function suck and I could call that officer my other function. Eso they go functions of awesome function suck. What you can also do is call a function from within a function. So, for example, in this first function, I could then call my 2nd 1 So you see here, I'll just space it out of it. So we have our first function, which prints the message functions are awesome. And then it caused this other function which will print the message function suck. So by calling this one, we're actually calling the 2nd 1 as well. So you see, if we run now, it's still printing both of the messages. So what we can also do if I just get rid of the second function, we can passing parameters. So these, like variables that we can pass into the function. So, example of this is if I am this function in these brackets here, we put our parameters or variables. I want to pass in a name and then in the print statement, all I'm going to say his name and then I'm just gonna add, thinks functions awesome. So I passed the name so Josh thinks functions awesome. Jack, think functions are awesome. Now you say that if we were to run this, we would get era because it says where my function, when we're calling it, is missing one required positional argument name. So this is saying is you're not passing in value for name, So that's all we have to do is inside these brackets. I'm just gonna pass in name. You could also have a local variable, so I could say name equals Jack. And then just pass in name like this, they both would be accepted. Now you say if we run it, it says Jack thinks functions are awesome, which is exactly what we want and what I think you can pass in multiple parameters. So I could pass in ah, to name sir name and other names, and I will say name plus and ah, plus other name plus, But think functions It's awesome said Now I've just formula the string here, So it's gonna be first name plus end plus the second name, plus both think functions awesomeness what their prince statements doing there. And if I just passed in Ah, Jack and then I do a comma because we ah now setting the value for our second parameter and I'll say, Jill. And here we go. If we were on this Jack and Jill Bug both think functional, awesome. And the way the beauty of functions is that we can really modulator code make it reusable. For example. I just can change one variable here to Josh, and it's going to run this function with, um, Josh is available. Or if I want, I could say OK, Jack and Josh and also will and, uh, Amy. And if I run this, you say that because both the messages at once so I can really reuse the code a lot here and change different values as part of it, which is really the beauty all phase. Another thing we can do with functions is return of value s o. What I could do here is I'm just going to get rid of this code here, and we'll do a new function on, and we'll call this one. Define too. Define our function and we call it Ah ah, some and we will pass into prominence. I end bay and I'm gonna do a column because we have to, and then we in dense on the next line. And I'm just going to use the return key word. So what this does is it will pass a value back when we call the function, and I'm just going to say return a plus B. So I'll explain what this is doing quickly. But if we were, when would you call this function? I said print some of one and three. 01 one and three. So what this is doing is it's, um I just made easier. Actually, I'll say my variable equals and then we'll print my variable. Okay, so we're calling the function. Some were passing in one and three as our parameters, and this is returning a plus B in this case, one plus three, which is four. And this return value is being set equal to my variable, and we're printing my variable to see what it is. So we should see that if we ran this at Prince four, which is what we would expect. Um, and it's working properly, so Ah, you may be questioning. Okay. Can we at return multiple values and no, you cannot Ah, you can pass in as many parameters as you'd like, but you can't return multiple values, so For example, um, I could do something like instead of some I could do area, and it just returns a Times B, and it would calculate their of a shape and you could do, like, area of a circle and including in, like, use pie and that kind of thing in it, Um, but it's up to you, so that's just the basics of functions and how they work. 19. Problem #8: Hello, everyone, and welcome to coding problem Number eight will jump right into this as this one's got to do with our functions that we've just learned. So you can obviously I go to that video if you're a bit hazy on it, l or if you're having trouble, rather than saying the solution straight away. So this one is, um, you're going to write a function to determine which, um, it's going to take in three parameters A, B and C, and it's going to return Which of them is the middle number, and I'll explain what that means in a minute. Um, but if you want, you can pour this video and copy in this template here. Obviously, the Hashtags are just comments. You'd only put those in how, but it's gonna be called deaf. Find underscore Middle, and it's going to take in a B and C and returned value here. It's just hard headed zero, but you will return the middle number off the three. That's what I mean by that eso. If we called, find middle with numbers for 12 you'll see that it should print to what I mean by that. So you So it's not middle is in what the middle number passed in. It is at the middle, as in are the actual numeric value off him. So if this was in the proper order, it like, um, ascending order, it will be 1 to 4 if he sorted them. Ah, and to would just to is in between one and four and again here. You see, if you passed in 0 400 negative 400. Um, zero is in zero is the number that's in between 400 negative. 400. And therefore, you should print there, so hopefully that helps. For example, if you had the numbers 15 and 10 at five is in between one and 10. So you'd print that? That's the way that one works. Eso you go program your solution. Now, um, pause the video as I'm going to move on to thes solution. Uh, and you will she pause it now as a movement that Okay, so we're going to move on to solution eso again? Go to this. You are Oh, like all the previous ones on you get taken to propel it on. And I believe this was problem number seven. So we'll load up that file and it's not its problem. Number eight. Sorry. So the way this one works is we've got our function here cold find middle and the way I have done this one is we've set how, um, numb. We've credit a list with a three element in it. That's a B and C. And what we can do with this list is sorted. So that will be sorted numerically. So it'll go. And then, ah, we're just going to return the middle value in that list. Now, I know that when, um, I first approached this question. Ah, and this is obviously at the best way to return it. I literally just did comparisons between injected vase greater than being great and see them returned that and so forth with B and C, that was obviously a different way of doing it. But this is very like, ah, moment where you go. Oh, that's so simple. But if your solutions work, then that's fine. A swell. Ah, But the way again, what's doing is turning into a list, because with this, we can then sort it. And obviously, if it sorted the middle number is gonna be the middle value in the list, which is just index one could remember. I list start from zero eso the index values for these would be 01 and two here, and one is being in the middle. Um, so if I would just debug here and print this numbs list, By the way, all this bottom bid is doing is just allowing you to input and then calling the function. You don't need to do that if you don't want to, you can just hard virgin. But if I want to run problem eight here and, uh, it is into the first value so far did zero 400 native 400. You see that all this list does is just sort it from hot, lowest to highest and then just get a little fire. You. That's the way that this solution works. And hopefully you were able to solve this problem 20. Classes: Okay, so now we're gonna be talking about classes. This is really a higher level concept and can sometimes be quiet, difficult to grasp. But this is very similar to functions in the way that they really help with making modular code, reusing sections of it and making minimizing time spent on programming. Eso that you can get a really good and functional ah, class or program. So classes are essentially a template. Allow you to make multiple copies of an object as such and modify its values individually. What do I mean by that? Well, as an example, um, if you're making a video again Ah, and we wanted to have different character classes like night elf. Um, Warlock, etcetera. Each of these would have different debts, like health armor damage, etcetera, um, and to stop us having to rewrite different or, like, copy and paste the same code, but just change a few different values for each class. What we could do is just have a single character class and be Adam make copies of that out with the relative unique values there. Thus, this eliminates the need to copy a lot of the same code, So I will jump into pie charm and I'll show you what I mean by that. Okay, So similar to ah, the way we define functions to define a class, we need to type class and we can give it a name, followed by a semi colon. So I'm just going to call this one. My Oh, we'll call this one character class. Don't. It's just them whatever you want on and, of course, having the calling after it. And then this means we need to invent anything inside of this class because that's the way Python works. And then we could simply have as many variables or functions insiders or any code we want that's related to the character class so we can reuse it later. What I mean by this is we could have, say, a health variable that defaults to 10. So what we could then do is if we go out of the indentation inside of this Ah, we essentially like functions. This code is never run unless it's called. And to create a class A we have to do is the class name, followed by two Collins. So I'm just going to sit in my very awards all credit variable here. And I'll call this one at night because that's gonna be the name of this class. What, this copy of the class as such And we'll set it equal to a new character class. And to do that, we just, uh, pass in the name and two brackets. So what we should find is that we can then below these print and then we could say night for a spell. It right don't health. So if we're hit, play here, I'll explain what's happening. You see, it prints 10. So what's happening here is we got outclassed out template that we can make it lots of copies off. And we've asked this variable to be equal to a new copy off this template. And in this template, the health is defaulted to 10. And we are just printing this copy off the templates. Health. So that's what's happening here. Um, and that's similar to the way it's working. Ah, but there are lots of other things we can do with classes, for example. Ah, we could change the health of it. So you could say night don't Health equals two. And now, if would hit play we'd say that it's printing to eso. We can adjust the variables to fit our preferences. Ah, and work the way we want them to. Okay, so the next thing we can do is put functions inside of his class, for example, we could say so inside of this week's a deaf and we could say, set up function. I'm just gonna call them, um, I would define and then the function name and then two brackets. And you say that this automatically put self in. So this is a special type of variable. And what it does, is it? Ah, it's automatically set to the instance off this class. Enough That made sense. What I'm saying is that this special copy off this class eyes equal herself and allows you to grab the variables from the class. Ah, it's just a python thing and something that you need to make sure that you do. Um, and it also increases readability off the coat. Ah, you see what I mean? A bit later on. So if we just got hit, enter here What we should be able to do so, you know, set up function. We could say something simple like print setting up character class. And you could see that what all we would need to do is go night, Daut set out function, and we just have to play. And you'd say it's printing that message, setting up character class right there, which is what we want are we goes to do something like set health, Take video five. Don't give me the call. And you say that if we I got rid of sending the health to to here and we call the set up function the health is not equal to five now, why is that? Because we aren't using this self fair will here. So what we need to do in order to modify this is do self dot health. It's just, um, imagine this, like doing night dot health here in this case, is doing self help. And now if we hit play, you'd see that it's setting the health of five, like expected. So you need to make sure that you using that self variable in order to, um, uh, access the variables properly and no have any issues there. We could also do two different things like damage local variables that damage If we say that's equally 40 and would say name is equal to not and what we can do The beauty of classes here is you can see that we ah can do eso We got night here. We could say elf equals a new instance The character class we could say Warlock equals a new instance The character class If I spell it writes corrector class. There we go. Eso This just allows you to really copy the code very quickly and make lots of changes to it. Now, what we can do also is have an initialization function. So what do I mean by that? So in, um, this is a special type of function. You need to make sure the name is ah proper here. So inside of this, if we go death and we do too underscores and we go and neat, um and then we passing the self bearable here. What this function does is it runs when the class created every single time. So I could print a message here is to show you what I mean. I could say of creating class, and you should see that if we had play here that is printed three times because we're creating three different copies off this class. What this also allows us to do is if we want pass in different parameters so I could pass in name, health and damage and then insiders initialization function. I could say self dot health equals health. Self dot Name equals name. Self dot damage equals damage. So what this is doing is getting the variables that are passed in and setting them to bay. It's heading the ones in the class to be called to them. So now what we need to do is pass in these values when we're creating the class, so you can say name. So, for example, this one will being night and then the health we can say 10 but a high damage of 20 or something. And then, for elf will say the notes elf and will say the health is going to bay highest, 20 bit of damage of 10. And then we can just do something similar for Warlock. Hey, can probably be beefy one or something like that. Ah, but you see, if we play now, um, it's not giving is in Paris. If we wanted to we could make this function display. Another special function we can use is if we get rid of this set up function here under death. Underscore underscores str impasse himself. What this does is this is what gets called when you print a cough when you use the print command on the class. Um and you can make it return a custom variable. So in this wholesale return and we need we can modify the string to be how if we want So I could say, um, under the name plus a colon Oh, name in a comma And then I'm sorry, I need you self dot name plus a comma plus health. And then I'll say and I'll do self the health floss a comma plus damage and then plus self don't damage. So I'll show you what this is doing in this second. So now if we were to go prince at the nights print l print Warlock and we run it, it's going to use this function to formats. The string. Now what you're seeing here is an error, and it's saying type air. It must be string. Know it. And that's because the health and the damage aren't text door strings. To do that, we can simply use str here and just encompass the damage and the health variables in that. And now we hit play. We should say that it's actually printing using this special function and formatting it properly. So you say the name of nine l four like health and the damage which has all been set properly So you can see that this is all working and hopefully this is helping to understand how this could be really helpful. And then, um, just to kind of show you how this could be used, you can pass in, Um, for example, if you were doing like a term based game or something or you would have to do is pass in like the variable ends, which is representing the character class and then just, um, minus the health and the damage from each of them. Ah, swear is if you were having to do different classes if you didn't use classes, sorry. And you had to manually do with damages and health. You can imagine how difficult it would get without these. And this is why this is extremely helpful and valuable. So remember the self variable is needed for three. The to be out to get the instance of the class in the special variables with underscores underneath um, do special things so you can say with the order complete year if I go deaf in due to underscores, there's lots of different special functions I can do, and I'm only using a few of them in this. But there's or get cold at different events or different things when you do it to the classes. So they're the main ones, and you could do the same thing with I said fruit. Or you could even do shopping lists. Ah, if they all had different this inside of them, it doesn't really matter. But that's the basics off classes. 21. Problem #9: Hello, everyone. End. Thank you for checking out problem number nine. So this one is got to do with classes s so you can obviously look back on that video. If you're struggling with on the way this one's gonna work is you will create a class with the name students are capitalists. Uh, and it should when you are first create a variable equal to this. An instance, this class it should be created with a name. So you should have to pass in a name and an i d. For this, said student. And this class should also have the following methods. Uh, with the capitalisation as such, so set h This should have signed the age of the students. So you should be out of set the age setting marks you should be out of set the Markovitz up 75. This is a number between theater and 100 Essentially, um, and that will set the market. The student, and then she ought to be out of print, the student class in a nicely format away. So we're gonna use our special underscore underscore string underscore on school, um, to be able to print their properly and it should be printed in the following format. It should be the name Colon. The students I D plus is plus assistants age years old and received plus thing mark out of 100 this year with the full stop. And if they don't have, if the person hasn't set the age or the marks, you should return it on the message saying Please have the angel marks of the student name . You can see that in the examples here as, for example, away setting s equal to a new instance to the student class passing in the name and the I d sir and and the I D 23 was said, calling this age part of it said he had 10 and the scent marks go to 80 and we're trying to print s obviously you sliding that. I'm just going to school string function, and it should print End column 23. So that's the name called I D is 10 years old and received 80 out of 100 this year because we set those relevant marks. But, um, here is an example. If we don't set the age of Mountain, you can see we don't call these set agents that mark. So therefore, they don't exist on the class on and we got a print. Assets says please said the age marks for Amy, which is the name of the student we pass in here with the i. D 53 note. I was just realized you haven't used this function before. Um, but to check if three class has age or Mark set, you could do like a bully in type thing, uh, in your function to say like, Oh, if he has eight remarks been, um, otherwise you can use this has attribute function inside of it, and you would pass himself, which is the instance of the class. Um, and then you would check for the property. So in here you do, like, string off just marks or whatever that whatever you named it. And this will just return if the class has that property in it. So you could say, like, if has attribute self comma, Age end has and ah equals false end has attribute self comma marks equals false. Then you would print this set this message otherwise you would print the one with the proper values because If you go to try and printer and this someone end Mark hasn't been set, you will get narrow. That's why he kind of need to do these checks first to ensure that you aren't going to crash your program because that's the last thing you want to do. So I'm going to run through the solution in a second. Pause the video here whilst you program your solution and, um, I will move on now. So obviously you can go to this. You are Oh, to see the solutions on this will open up the repellent. And this was problem number nine. So we'll go to that file and you can see this is a bit of a bigger one compared to our other problems. Ah, and you see, we have class students. So that's how we initialize there. Close. We've got the correct name here, and we have how underscore net function. So this is where we pass in the name and the i T. And we're setting the local parables. That's why we're using self so self name equals what we passed in himself. The i d e go. What a pass! In the reason ideas in capital is because if we use lower case, I d. That's a special function that python is to find. So you will get errors if you try to use that. So don't use low case I d. Because you made running to issues with piping Leah. What, you're using this wrong when in fact, it's your just trying to name affair that eso That's where that issue is coming in. As you can see, we have also agents. It marks functions. So that is just parting in age and marks and setting the local instance of that to be what we passed in. And then we have this underscoring the school string function, which is what gets called when we try to print in its sense of the class. And we're checking if has attribute. H End has a tribute. Marks then will print this nicely formatted string. Of course, remembering to yourself here cause we can't use just name plainly organ issues. I will say there's no variable called name. That's why we need to yourself. Uh and that's just for manning it. So using the name that I D. Uh, the age of the marks are remembering to set these to be strength because they may have been passed in this numbers and you will get a dollar errors there and track and can make numbers and just does not work. So you need to make sure you turn them into strings. Even if the our strings already this won't hurt. I like to overuse it. No problems there. Otherwise, if they don't have the attributes, age and monks would just return this, please of the agent mark for And they're just passed in the name here cause they're always gonna have the name. Because in order to call this function, you need a pass in the name, as in order to Ukrainian since the class, you need to pass in the name into this and it function. So you can see here where train these Giunti five was to run at problem nine. You see that? Um, this 1st 1 is pretty a and 23 years old and received 80 other 100 this year. Where is the 2nd 1? Was asking when we try to print it, ask for the age and marks for the student Amy, which is what we expect. Obviously, if you did just like the different other ways of doing this without using this has a tribute. Could have Bean. You might have had a variable up here which was like set marks defaults to false and also set. Um, what was the whole thing? Age eagles false. And then in these, you could say, OK, we've set the marks true. And we've set age equals true and you could just check if set age and set marks some things like that. Ah, you'll do self dot said age and self doubt set monks. But you understand, uh, how this works. Uh, just like that. That would be how you do it and also appear you would default self dot set age and self set marks to be false. And that would be another way of doing it without using that has attribute flag. But that has a tribute once just a nicer way of cleaning things up. And then you don't run into this ugly mess that we have here. Eso Hopefully you got that problem that these classes are a lot more difficult on, and usually thesis more like second year university course content that you would be looking into and they are. You really do need to learn them because they yes, so, so, so useful when using object oriented programming. 22. Dictionaries: Hello, everyone. And welcome back. Now we're going to be talking about dictionary. So essentially, these are similar to our lists, but work with keys and values instead. So what I mean by that is, for example, if we had a phone book, so create available phone book and also this to a new dictionary. So to do this, we use curly brackets like so, um and that's what we need to do to initialize a dictionary. So what you can then do is say phone book like our lists. And we could say, OK, Jack, his number is going to be equal to, um 93 else. 93 A love of probable something like that. Um, and what this is doing, is it setting the value? Uh, Jack? What? It's setting the key. So use. I imagine it like a door. You used the K to get the value. So you need a K in order to get in and figure out what's inside or like a ah locked safe or something like that. So what this is doing in this case, the case, Jack and the value is the number we've assigned to it, and we can say, Ah, lots of similar things that you say, Jill. Okay, Her number is going to be that one. It doesn't really matter. In just for clarity, it probably print the phone book here and hit play. You would see that it's got the different pairs and values so you can see the keys, Jack. And then there's number and the keys. Jewell. And then there's her number. Um, if you're wondering about how to initialize a dictionary with stuff in it, a gimmick. Ah is very simple. I'm just going to here until you can go over multiple lines with this. And I could say, OK, Fred. And then we do a colon and I'll say this is his number and I could do a common say Okay, George. And to a colon and then say OK, that's his number and so forth. And you see, if I play now, it's called those values already included. So, um, when you are going through each element in a dictionary using young loops, you can actually get multiple variables for this. And what I mean by that is, ah, I'll show you here. So if we did a for loop here Normally we would go okay for its thing in phone book if it was a list in this case, what will say is OK, forage K and forage value So we can do a comma here because there are multiple variables in phone book dot items and because, um, we are calling a function inside of phone book here. We need the two brackets end because it's a four live. We put a colon on the end and we could simply say print. Okay, uh K And then I could just put the key here, and then I could say, OK, um, what's a good? OK, and then I'll say value and are just add the value onto the end there. Now, obviously the value is going to be a number, so I'm going to make sure that that's got a string wrapper around it. But if we have playing out, you say, Ah, that the case, obviously the names and then the values is three numbers. You can say that all here they got fed, which is the case and the number which is the value in the dictionary. So how do we remove certain things? Will the great Ah, thing about this is if we just have the K, we can remove the value automatically so we could say something like Delete so short for the late is dealt phone book. And I could say, OK, I want to get rid of Fred. And if we play now, you'll say that Fred is no longer in our list because we got rid of him. Eso That's simple way of doing it. You just to Italy and then the dictionary name plus the square brackets And the key in this case, the name of the person. Ah, in other ways of doing it is like how lists we could do Phone book dot pop. And we could say, Okay, we want to get rid of George this time. And obviously this case tentative that obviously this is case sensitive. If the G was located, would not get rid of him. But you say this getting rid of George now and friends back in. So that's simply getting read off. Ah p A case from dictionaries if you want to check if something's in a dictionary. So, for example, if I wanted to say if ah Phillip is in phone book. That's simply what I do with my statement. I could say OK, Phillips is in the phone book and I hit Play here and you'll say that message isn't being printed B If I said if Philip, if I did not If Phillipe, if I made it, say, If Philip is not in the phone book than I will print the message, um, it's not in the phone book and I hit play. Now you say it's putting that message because he isn't in the phone book. Eso that's ah basics. Four dictionaries. Obviously, there are multiple other methods you can do with dictionaries. You can copy them ah, similar to lists. Ah, and you can get their values separately. Ah, instead of the items. So items in this for Luke gets a triple, which we discussed earlier. Ah, with the key and the value in it. You could also to phone book by itself, which will get your case. Any curiosity of phone book dot values, which would get you values if you don't want both the variables, but usually you do so that's why you would use dot items in this case 23. Problem #10: Hello, everyone. And welcome to problem number 10 s. Oh, this one is going to be using dictionaries. Eso if you haven't heard of the game called Scrabble, the way it works is you try and create words with the most points Had that fit on a grid. But what? I'm gonna worry about the grid bit. We're going to basically determine how many points a wood is worth. Eso you can see here, Um, we are giving. You were given a dictionary called scores, and it has every letter in the alphabet, Ader said, With a new miracle value, which is what it's represents in the game and using this dictionary are give you willing to it later on. You need to write a program that asks user for word, and it will, um you will need to add up the score of the word and print out that score s O. For example, if you put in Quiz, it should output 22. That is because she was able to 10. Plus you, if I can see it is a good one. Plus, Isaac producer, that's 12 of moment. Plus is Edward Siegel. Another 10 which is 22 in total. The same for zebra and elephant apples. 13 and 16 respectively. If you want to quickly positive video here, you can grab the code for the dictionary. That's just this scores. Dictionary said after type. It'll out again? Ah, here a bit. Lee bit away slash to our end. P one feet. I preach other to know. Maybe. Is there the, um you will have to double check on that. If that isn't working, that's so you can go, right? Your solution now, and pause the video as I'm going to move on to my solution and explain how I did this, Uh, problem. Okay. S sort of UAL decisions. You can just go to your row, which will take you to the Republic and problems tell is just here. So open that up. You can say this is thescore stick show. It's been more ugly formatted here. Uh, but that's essentially the same thing. Ah, and we're setting. But first, what we're doing is we're getting import the word that the users importing and where initializing this total variable as it is gonna be the total score of the word and would be way starting it at zero. And then we're going through each letter in this world that we important. And we're saying total equals total plus whatever the school. But the current letter, where on is so are just, uh, not used plus equals here in case that confuses you. But this is essentially the same as what that line was doing, as he was saying, Total so zero equals zero. Plus, um, the scores dictionary, the value of the numerical value of whatever the current letter were honest and then total would be able to say tuna, and it'll be called a 345 and eventually add up each time we go through each letter in the word and then what is printing that at the end? So if I would try and run a problem Number 10 and we would have putting quiz, we should say that we get 22 because the way it's going uses going okay for each letter. So cute that's going total is currently good. It's so totals equals zero. Plus, we're getting the value of two, which is 10 If I can see it. Eso a passing in this key for the Dictionary of Q on its returning. It's this numerical value 10 and it's doing the same for you with one eye with one and as e with 10. And it's adding that to total H time, and then it's printing it at the end. That's how we get the 22. So that was a harder problem. Um, require you to think a bit more differently and hopefully you've got a similar solution, if not the same one. 24. Libraries: Hello, everyone. And welcome back. Now we're going to be talking about libraries, so libraries are a way that we can access other code in other files whether that be our own curd or other people's code. So particular python actually comes with some libraries built into it that you can use, and you first need to import them before you actually able to use those libraries. And python actually stops you from like it doesn't import them by default because it can be confusing, and there be lots of different functions that you might accidentally call. So to fix this, you only are allowed to import what you using or are going to use eso the way that we do. This is up the top of any of our files. So we have our main dupuy file here. We use this import keyword, and we can then follow this by the name of the library. So, for example, we may want to import the operating system module or O s model. So we say Import os, And then we could say something along lines of, um print os dot get C w date. And that stands for OS. Get current working directory and you see here it actually prints say, users use a patch on projects to toil projects because that is the directory that this file is in at. So you can see that without this important line here, if we would have run it, we'd say Are named Os is not find however we actually, there are a few different ways we can uses Import meant, for example, if we didn't want to import everything in this library, we could say from OS import, get C W dink. We don't put brackets around it and then all we would have to say is, Just get can't working Director. You don't even have to have the OS in front of it now. And you can say that that runs properly and gives us the expected output you could also, if you prefer this intact safe from us import, it's Astra's, which means import everything. The same is just going import OS, and you can also ah, import thing, multiple different things. Using common sigan se from always import get to come working directory and you could say Ah , the system command as well as another one on this allows you to adjust, chain and import as many different things you would like, or you can obviously important all at once. So that's Ah, using that import semen, you can also import them as different names. For example, if you already have a function called get CWD and you want to use this OS moderate, you can say from OS Import, get current working directory as and we can name it whatever we want. So you could say my new function. And then down here we would just say print my knee function, and it will actually call that get set of EU de method, but allow us to use whatever name we specify here. And of course, you can import multiple things using commas again with that syntax. So that's, Ah, this OS model that we comes by default with pythons. So other libraries you may have to install yourself, and we'll move on to that in a minute. But other helpful ones, for example, is the random library, which allows you to generate random numbers so we can just say from random, important whatever we want to important here, I'm going to import the rand range function And what we can then say is this allows us to generate a random number within a range, so we could say print rand range, and we can posit in a few different variables here. We pass it in the start so we could say five and we could say up to 100. And we can actually then print run this here and you say it's Jared 52 this time 47. So it isn't, in fact, random. And they're not going above 100 or below five, which is what we placed in here. But if we would have say 1000 Now, you see that we start getting some big numbers, like 800 here. So that's this random library. Other things from this you may want to use is the choice method. So we can import that again. Him. And this allows you to say we have a list of fruit and would just set this to a list with something like apple, uh, orange on by, none up. And we want to pick a random item from this list. We can simply just save print fruit. Don't choice. Ah, actually, sorry about that. We would just say print choice and passing the list we want to use. So we're passing in this brutalist here, Run that. You say we've got orange orange again. Accidentally took the wrong button There it played in banana. This time on, maybe banana orange pair they go and there will be Apple is well, eventually. It's just the one in four chance. So that's how you would easily pick between, uh and I'd amount of a list of well, if you didn't want to use that rand range function either. So those are the two main parts of this random library. Obviously, there's lots of different functions and models in these libraries that you can play with and choose to use yourself. But for now, ah, you can just import them and use them as you see fit. So another library we may want to use is the requests library. So this allows us to actually send ah, a request to a U R l Laurene p I that we may want to use on the Internet and receive a response from that. So what we need to do here is we can say import requests with an S on the end there. And you say we actually have a red underline. So this model isn't actually shipped as part off human as a sorry is part of a python and to actually install it, we can use pi charms internal tools here so we could go to the file tab on and then we can click Ah, settings. And you say I've already got it selected. He But you go to the whatever the project urine is and then click Project Interpret up and you'll see we currently have two packages installed, pip and set up tools So we'll leave them be and we can actually click this plus on the side here, and we can search for all of the available packages that are made online by craters and random people from the Internet. So there's generally speaking lots of different ones, and you'll find one that suits your needs if you wandered and the package we're gonna be searching for is requests right now so we can just click install package once we've got that selected, and it should download it from the Internet and install it for us so that we don't have to even bother downloading it externally ourselves and you could see your package installed successfully. And this read online has now gone. So AP eyes are available online for programs to work with. And the A p I we're going to work with is just called an open emoji ap I So I just went to this website. I googled emoji FBI and came across Islam. I had to get an A p I K. Which you'll find a lot of sites will require from U. S. O that people don't just abuse their services. And ah, I just gonna scroll down here and you can see they've actually given us the barrels that we need to go to to get the different features off it. So if we wanted to, for example, get a list of all emojis ever, then we will just go to the Earl kcbs emoji FBI dot com for such emerges and put in the access key here. So I'm just going to copy that you Earl over into Python here, and we're going to type of bitter code using this request library so we could say, Oh, well, stand that, for our question equals requests don't get eso that get is actually just referring to, um, what you'd usually do when you load a webpage and we need to put in the URL here. And I would just quickly copy it over here, and you consider the end here we have the as access key equals one to whatever. I'm just going to replace this with the access key I was given. So just copy and paste it in with whatever one you got and the former we actually get this back in is called Jason. So it's a special, ah, syntax used in files and a lot of programs will use it. And if you have used on the programming languages before, you probably have seen it. And it's just a way of structuring dot and now requests automatically has some functions in built so that we can interpret Jason easily and convert it to a python dictionary s. So we can just say that our, um, response is equal to our dot Jason so that will actually get it for us because we already know that it's going to get a return or Jason, and I'm just gonna repeat print the response here and we'll see what we get. So if we hit run now you'll see it takes a minute whilst it pings that website or that paint. And we have a long dictionary with lots of information and obviously there's a lot of different emerges so we don't have to. We won't actually let us girl anyway, but if we actually go back to this open emerging page, we can see the type of format we get it back in. So we have a list and each one of these is its own emoji circuit is the slug character Unicode in and Cut Point Group and subgroup. The thing we're interested in is this code point here, So to simply get it out Ah, we just use our dictionary skills so we will actually say full each emoji in this list. So in response, we're gonna It is printed so close. I print emoji and remember, without dictionaries, we need to get the key. So the key name we want is actually going to be a slug. Sorry, no slug character and that will give us the actual Unicode character code Witches. How all the modus directly Stort and Python will interpret this. If we hit play, it'll get the request and hopefully it should print it for us. Ah, and we wait a minute and they go. We can see all of these different emerges there in black and white for us, Bill. It's all right there. Still Emojis, and you can see that they're all printing eso there Bean received from this year also were actually visit this euro in a Web browser. We can see the kind of response we'd expect to get back so I can actually bring this tab over here now. And you say it's just a big along Jason file and we're just grabbing out this character value, which is equal to these backs last. You random numbers, etcetera, and python is actually printing that, uh, any food of such character. You can see how many different emerges air actually here and how the role being printed. So this actually will automatically update with any new ones as well, Which is awesome to see. So that's it for this emoji library. At one last library we want to check out is the color model the term color module, so we can say import term color you see we're going to run on the line because we need to go to our settings and now interpreter and make sure add the term color model and making sure it's this one without any extra Syntex on it. Hit, install. Wait for that green light and we should be good to go. So the way this time color what this does is allows us to print context. So, for example, we could say print. Ah, Jack is amazing. And you'd say that if we were to run this at just printed in black, that's been boring. So if you want a fancy up your text of it, we could set use this colored function, which is imported from term color, and we just do a comma inside of it and passing the color we would like so we could say screen, for example, and you'll see that. Hopefully, uh, this isn't this is giving us to read underlying cause. It can't figure out where color is meant to be from. So I can say from term color import colored, and that should help fix it. Sometimes it does its work with just importing, and sometimes it doesn't and you say we have green text right here saying Jack is amazing, which is going to see, And we could change that to read, and you can see that's working as expected. If you wanted to make it, blend in with the rest blue. Obviously, there's a big long list of different text colors from greater white and highlights that you can use. But this is just one example of another library that you might want to important to your projects and use later on. Now, this is for importing external libraries. But how about importing other Pilon felt that we have written? So you see, I have this other filed a pie right here. Inside this, we have a variable called Secret que in That's equal to string, which has the value of a B, C 123 and say we wanted to import this secret que and use it in this file. Then we can easily do that. We just first check that these tour in the same directory. Otherwise you'd have to give the directory location to import from him. We can simply say from of the file import Sacred K, and then we can just print this and you say that if we run it were actually getting that secret K A, B, C 123 from the other file. And everything is actually working properly so you can import everything from other files to get it to run. Or you can import functions from that You may well, of course, he might have a utility class. Ah, and you can really, at this extremely useful. If you want Teoh say, for example, the other file was up a level. You can put a dot in front of the directory name, and it will actually look in files above it as well. Or two dots if you wanted to look too far above etcetera, and that is how you would import other falls into your python program and run the code in them. 25. Scope: Hello, Ron. And now we're going to be talking about scope and global and local variables. So essentially, we're going to variables can only be access by certain parts off your coat on. And it's very difficult to you may have encountered issues where things weren't working because of scope, and I'll try and explain how you could fix those. So, for example, say we had a function. Well, we just define it and call it my funk, just giving it a name. And inside this function, we are going to say X equals 300. And then we will print X, and we would just call my function. And if we were on this card, will see that it's just printing 300 which is exactly what we would expect. Ah, and it works properly. So how about if we had this variable outside of this function and we say X equals 500? Now we're to run it still printing 300. Okay. It must be setting x A go to 300. What about if we instead, after you're on the function so well, remove this print statement here, so running the function sets ex eagle 300 outside of here, we will print thanks. So X starts off his 500 we call the function ex, get set the 300 then we print it. Once we've run that function, you'll say that this is actually printing 500 because variables have scope, which means an area that they can be accessed and modified in. So you see that this is considered the global scope because it's accessible by all of the file. Whereas inside this function, this variable is actually only accessible within it, and it doesn't actually modifying anything else outside of it unless it specifically told to. So if we were to want to fix this and say, Hey, used the global variable X So this one that's available everywhere rather than the local one, we could say Global X, and if we would hit run, You say it's now putting 300 because we've told it. We want you to actually use the one that is outside of this function, and it works properly. Ah, if we were to ah, if we were to try and put a function inside of a function So you say this my funks X equal to 300 we did find my in a funk. And in here we would've print exe. We will say that if we just remove that last line at the X is actually not getting printed , it'll cause we're not calling that function yet. So we say my inner function hit play. You say that's pretty 300 because this variable X is accessible by everything inside of this function, including other things that are indented further or, in this case, other functions. Eso That's how scope is read and understood, and it can be a bit confusing ends. This is kind of how what you need to be careful off when you're using other variables, because you may want to change them at. So, for example, we used that global keyword to say used the global variable, and that will allow us to use that specifically, so that's essentials of scope on. And if you're asked to describe the scope, for example of, say, this function, this variable here X, you'd say its scope is limited to inside my function, whereas this one is the scope is not limited because it's accessible anywhere. Buy it. So that's global and local variables is just something to keep in mind when you were programming s so that you don't run into any issues. 26. File Handling: Hello, everyone. And welcome back. Now we're going to be discussing file handling, so we'll jump right into it. I have my file here, my text file info dot tanks T and has just got, ah, the lyrics to Happy Birthday in it. So only a few lines there and we're going to try and read and write from it. So to begin with, we use this special open keyword, so we'll set our variable F four stands for file here. Equal Do open. This is a function in built into python. You don't need any libraries for it. And we putting a string here, which is the location of the text file. We wish to open eso because it's in the same directory as Al Python file. We don't need to put in the U N role for, but we just put the file name so we can say info dot txt And then we also require another, um, parameter here and the possible options for this is it's some strings him, and I'll just comment here what we can put. So we have, uh, which is for reading. We have languages for a pending, which is where we can put a, um, add to the end of a farm, but no overwrite what's there and then we have right or W, which allows us to write over the whole file. And if we use W, it will create the foul if it doesn't exist along with a pent. But Reid will cause an error if the fall cannot be found and X is a great and that just creates a file and returns an error. If there's one there already, Um and we can also put Bill t for textile binary, but we won't worry about that. So to start with the we're gonna open in read mode because we want to be out of read from it Ah, which is easily, easy to do. So once we have opened up, we can actually just simply type print f don't read. And we should actually say that if we could play here, we get all of the lyrics as expected. Ah, on each individual line, which is actually what we want, we can actually pass in Ah ah number here. So we could put in five, for example. And you see, it actually just reads the 1st 5 characters or letters. Ah, not the 1st 5 light, so don't get confused by that. But we could also use a read line method, for example, which just read the whole line. And you say it prints Happy birthday to you the first line there. And we could say if we wanted to do it this way. So if we wanted to actually loop through each of the ah lines in it, we could. There's a few different ways we could do it. We could actually just you call this read line multiple times. So you say if we put to print statements there, it actually prints at the first line twice. So this red line will only actually read the current line you're up to. Whereas if we want to read each line individually may be stored in a variable or something like that that we would use a for loop so we could say four each line or name that variable whatever you would like in F, which is what we named available here. And we could say print line and you say that we are getting all of these printed. Probably now there's a few issues one is that you concede there's lots of spaces in between where there shouldn't be. Now, why is this? Well, text documents actually contain an invisible character. At the end of each line. It's back slash and so what this actually does is it's a new line character and indicates that this is actually end of the line s so that computers know to read and move onto the next one. When you print backslash in, it will in the console automatically put a new line there. So what's happening is it's printing the line with that bag slash in which is creating the new line. But this print Simon is also creating a new line as well. So that's where we getting the double ups. So to fix this, we could say at line equals line dot strip, So this removes any of the invisible. Hidden are encoding or markings on that line, such as that backslash ending. You say we play here, we have it formatted as expected, and we the advantage of looping through like this is that we could add ah, formatting to it. For example, we could say a count equals zero or light line numb is probably a better variable line. Numb equals one. And at the end of this loop would just say line NUM plus equals one which adds one to it every time. And in this print statement, we can just say we want to print the line numb at the start of each line. Uh, so it's easy to see and making sure that we use str to convert that interject into a string . And you see, we have won three denied, which is the line number. So you can see how using for loops, for this is a lot more of a better option. That doesn't sound very good, but you understand where I'm coming from. So what happened if we wanted to say append to the end of this fall? So add something to the end of it at New Line toe Happy birthday at what we can then say is , before we actually do any of the printing of it, we will say something along lines of don't right. And we could say what should be this line we're going to add to it. Uh, something along the lines of happy birthday ending would just put that there for now and you say that if we play we actually get an error because it's saying unsupported operation not right, herbal. So that's because we're actually right at opening it in read mode, not a right or a pen mode. So if we actually changes are to an eight and hit play, I accidentally hit the debug button. Stop play. You see, we're still getting the not readable Aaron Ele so we can actually put multiple different methods here so we can say our and a which means which doesn't actually work. Some of them you can combine. But this one obviously not eso for this we could change it to W which will overwrite everything in there. Ah, it says no readable. The reasoning for that is we can use the plus symbol which will actually allowed to be read as well. So we can say a plus, which means upend plus read and you say it runs properly, doesn't give us a narrow. And we look at this text file and you see, we've added happy birthday ending onto it. Now I'm just going to leave it for now. But what happened is you can see it's added it to the same line. We don't want that. So we actually have to add this and new line character run to the start of it so we can say backslide and and if we hit play now, will say that's actually added Happy birthday ending onto that second line for us, which is exactly what you want. And we were actually to play this multiple times because we're in a penned mode. It doesn't actually overwrite. One is there to begin with. Instead, it adds it to the bottom off it so we can fix this. If we were the one over idea, we changes a to a w, which means over right, and if we hit play now you see that it's actually gotten rid of everything. We have that empty line at the start because of that backslash in which we would no longer need. Now eso weaken. Just remove that hit play and you'll see that we have it on the one line like we'd want. Now we aren't doing one thing that we should have been doing, which is actually closing the fire when we're done using it. So we just need to simply say f dot clothes. Now, this isn't an issue because we are. Actually, the program ends once we're done with this operation. But if your program wants to keep doing other things, then that vile wouldn't have saved properly. But that is the probably do things, making sure to close it as you would want. So how about deleting files? Well, to do that, we can use a special library. So I'm just going to leave what we have here, and we're gonna import OS, which is the operating system module own library. And we just simply can say oh s dot removed. And we would just passing a string with the file name or location, much like before. And for this one, we can say info. Don't take state anti foot hit. Run him. You'll see that infinite takes he gets removed and is deleted permanently. So make sure you're very, very careful out with this. Ah, you may run into residue. So if I hit play now, you see we actually get in error because that's saying, Oh, this system cannot find that file name because it's actually gone, so you can always add a if statement up the top of these That says, if oaths dot past dot Weber if oeste a path that exists and pass in the file name here so info dot text a was what we called it if I can actually spell and we use our comma colon here And you said that this removed function, uh, only gets called now if that file exists and when no longer getting errors. So you should always before you use that remove ah, check to see that the final actually does exist first. And if we were at it now so if we would have writing on a patrol project clicking new intellect file and name it info hit Okay, so it's a text fall and put some random live, isn't it? Save it and he played. That is gone because it doesn't have fall extension, sir, I can just quickly refractor her name info dot take stream. Part of me never rubber Blart saying it's open, but that's what is complaining about. Take to rename info dot text a little cards found era, but I'm just gonna relate it and try again. Okay. Why is this being annoying? So an explorer, would it still manually move over here. You say this didn't actually give a fall extension, Remember? Did that. So we'll just create new text document info dot txt there. Piers here properly. Flubber, Blur hit. Play the lates and doesn't give us narrow. And if we play again, we don't get narrow because we have that statement checking to see if it exists. So that's all working properly. Obviously you change that name according to where you want to delete a file on edit and right, But that is how you do basic file handling in Piketon. 27. GUI'S: Hello, Ron. And now we're going to be working on easy going and just covering the basics of how that works in Piketon. So easy. Gooey is a library that we can use. Python does have an in built you why library called T k NDA. But that can be quite complicated. And it's probably out of the scope of this country tutorial. So for now we're going to be using this library, and it's an external one. So we need to make sure that we import and it all it. So we go to file settings, making sure to click our product him and click Project Interpreter. Now, once we click this plus, we should be out of search. Nice and easy, easy going. And it's the 2nd 1 right there making sure to install that package with the latest version . So we got the green light, so we should now simply just be out of you from easy going import star or import everything . And you say we don't have a read on the line because it has installed that package correctly. So what is easy going? Whoa, let's just use the demo finance. So he called E G demo and hit play and you'll see that we have this nice You I appear and you can see it's actually giving us a list of all the different elements that we can include in Are you wise? So we have a message. Bartsch box, click a case. What matches? Box looks like button box one box looks like. And we could say we want to look at say they even have file opening boxes like this and so forth. We could have a even a multiple choice box, so they go pick something. Cancel. Okay, etcetera. And how do we exit out of this? Cancel. Maybe. Hey, there we go. S so that's a demo designed by the people who made the library just to show you how it works and all the different elements in it. So that's what your you and will look like eventually. So I'm just gonna run you through the basic components that you can use with easy going sort of first things. First we can say, Ah, message box. And you say that Papa John's or in telling us what the different things we need in this are . So we have a message. So it's whatever we want to tell the user. So we could say Welcome to my amazing program and we can actually set the title, which is what is at the top off the window. So we could say title is the best program ever, and we could even, ah, change the button that we press. So if we would actually run this now, you hit play, you can see our title is the best program ever. And text here is welcome to my amazing program. You see, this button is okay. Uh, we can actually change the text of that. So you could say, continue on or something like that. You can change whatever you want. Continue, aren't you? See that one change? Probably. Once we click it, it runs the Kurt after it. That's what a message boxes used for us. Like a prince statement for you eyes. So, um, now other parts that we might want to use we could even specify the different type of message boxes. So if we were to change the title here to warning Actually, that isn't what we need to do for this. At the moment, we could use a choice box, for example. So I'll put those customization were back. But we could do a multiple choice box so we can use our list here for the possible choices . So that's choices equals a list here. And we could say, um well, maybe a favor fruit or something. So it's him banana If I couldn't spell it. Ah, Happel Orange. Okay, I give up etcetera, and we can then call and produce a choice box with the message in it. So maybe what is your favorite fruit? And we just simply say choices because this list that we made court choices it play once we click. Continue one. You see what is your favorite fruit and were given the different options. If you double click on them, it will automatically move on for you. But how will we actually get whatever they click? So we can set a variable here so we could say out response equals this end just for debugging purposes will print that response to see what it was that we actually click self . We would act like apple fanatic Agok You see that we've printed apple, which is what we want because they clicked on that so we can actually get input from the users and do things accordingly. For that s O. That's how you would use a choice. Boxes, which will give you a list of different things and whatever they click on it will output it for you. So other box, other different elements. You could use this, for example, a bull box. Certs again, that quite self explanatory. We could say whatever the message is gonna be here. So, um, an amazing message. I'm getting less creative as we do this the title. So that's going to pay my amazing title. And of course, we can give it three options here. So again, another least then we could say option one an option to here hitting play on the way. Continue. Select our fruit and you say much like this. We have options in the form of buttons rather than, um selecting them like we did in the other one. So it's really up to you. However, you'd like to customise this and the different options you would choose. We can also add images with the image keyword, so you could just simply say image because whatever the location of the images it up to you . I don't have one right now, but that would put it on the message box for you on and so forth. We can have ah, choice boxes. Like we said, which is easy. And we also it can do multiple choice boxes. So ah, here we have a regular choice box. But we could change this. So that's a malt choice box. And if we hit, run here, continue and you see that we can actually select multiple different things. So and if would hit arcane now when no longer actually printing what? They clicked Army. So we'll just print response. And now if we would click it, you say we select been honorable Click OK, and we get given a list which has all of the different things they selected. So if you want to do selections, that will be the way you do it with the multi choice box function. Um, now what about if we want to get ah value from the user? Well, that's a nice since before we could say what is their name. So we could say name is equal to enter box. What is your name says just the messages going topia, and we don't actually have to put total if you don't want it. So I will get past days option two and then we get what is the name? So you could say, Jack, we're not actually printing it, but name would be set toe whatever they entered just cause we're getting a bit chaotic, Er, just get rid of those things above it. So that's an enter pox that we could also change this to and indeed your box, which will give us a number so we could say into your box. And this could be changed your age, for example, we print this down here, continue on with what is raid. We could say if we were to put in a name, for example. Okay, the value, though you entered Jack is not a number. So will actually do that detection and correction for you so that you can only enter a number now if we put that value in. It says that value entered is greater than the upper bound of 19 9 So what that is actually referring to is it has a minimum maximum at set in by default. So to fix this. I believe it's Max. There's a special key word that you can use here that will allow you to change the different highs and lows that are allowed so that you can adjust them accordingly. So simply to add this, we just simply the we just put a variable him. It's called her Low bound equals whatever the number is. So we could say negative 1000. And we can also say up abound equals whatever that number is there. And you say that if we hit play now and we going into a larger number, probably not that large that we don't get that there any more. And it's printed properly s so you can adjust that lower in upper band, however you see fit so that you don't run into any of those issues. So other things you could do is if you maybe wanted to displace, um, code, you could say code box. Of course, this we could put the python in years of print. Hello, world. This is a bit on making sure to use different quotes here. Hello world they go. That's the message in it So blah and toe value. The enters non integer. Okay, put it number and the year it's actually this is what the code box looks like. It will not do any syntax highlighting for you. You have to program that yourself, but it's just an easy way to maybe share code if you want to do that. But there's a lot of different windows and boxes you can use as part of easy Good at the main ones Are there enter and exit boxers? Ah, you could also do a password box, for example. So we could say password. The variable is equal to a password box. Ah, enter a secure password, please. And if we hit run now, Blah and her intimates interesting group possibilities. You see, whatever we're entering is actually getting automatically hidden from us. If we were to try and copy and paste this, it actually doesn't let us. So it's actually quite good in that respect. If we had okay, you say that the password isn't actually printing, but it would set that variable password to whatever they actually the imports. Okay, Now you see that this was whatever I am put it is the past would and it's bean received properly and we can then save that in the database if we need to do so on and so on and so forth. There's also directory open boxes and felt saves and that kind of thing. But you can explore that in your own time at the documentation is available at If you to search for easy, gooey documentation. There's a wonderful sight with lots of different examples on that kind of thing and that you can go to so that's it for easy going, and you can experiment on your own with it.