Programming with Python: Hands-On Introduction for Beginners | Febin George | Skillshare

Programming with Python: Hands-On Introduction for Beginners

Febin George, Software Developer

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
30 Lessons (3h)
    • 1. 1. Introduction and Course Structure

      3:25
    • 2. 2.1 Installation for Windows

      6:46
    • 3. 2.2 Installation for Mac OS

      6:27
    • 4. 2.3 Installation for Linux

      6:58
    • 5. 3.1 What is a variable and how to define one

      4:07
    • 6. 3.2 Rules to define a variable

      3:33
    • 7. 3.3 Data Types

      2:21
    • 8. 4. Numbers

      3:41
    • 9. 5.1 What are operators ?

      3:16
    • 10. 5.2 Different types of operators

      13:15
    • 11. 6.1 What is a string and how to define one ?

      10:26
    • 12. 6.2 String Operations

      7:09
    • 13. 7.1 What is a list and how to create one ?

      3:51
    • 14. 7.2 List operations

      7:18
    • 15. 8. What is a tuple and how to create one ?

      4:34
    • 16. 9.1 What is a dictionary and how to create one ?

      4:59
    • 17. 9.2 Dictionary Operations

      6:57
    • 18. 10.1 What are conditional statements ?

      2:01
    • 19. 10.2 Different types of conditional statements

      8:40
    • 20. 10.3 Using logical operators in conditional statements

      8:20
    • 21. 10.4 Program - Check if a number is multiple of 3 and 7

      7:54
    • 22. 11.1 What are looping statements and implementation of For loop in Python

      5:20
    • 23. 11.2 While loop implementation in Python

      3:48
    • 24. 11.3 Nested loops implementation in Python

      4:21
    • 25. 11.4 Break, Continue and Else

      9:10
    • 26. 11.5 Program - Check if a book exists in your collection of books

      6:49
    • 27. 12.1 What are functions and how to define one ?

      4:00
    • 28. 12.2 Functions with parameters and return values

      7:40
    • 29. 12.3 Program - Find the greatest among two numbers

      7:00
    • 30. 13. What is exception handling and how to handle exceptions in Python

      6:53
37 students are watching this class

About This Class

This course has been specifically designed for beginners who have been looking to obtain a hands-on learning experience with Python, teaching you concepts of programming right from the basics and Python being the most simplest language for a beginner to start with.

It is the right time to start learning the in-demand Python language because of its gaining popularity in the fields on Data Science, Backend Development, Internet of Things, etc. Keep yourself equipped with the most sought-after skills!

A lot of exercise problems, programming lectures, PDF notes have been included to provide you with a great learning experience!

You will work on a project at the end of this course, which has been designed for you to implement all the topics which you would have mastered by the end of this course to give you enough confidence to start writing your own independent programs in Python.

Transcripts

1. 1. Introduction and Course Structure: Hello and welcome to the school's thanks for enrolling, and I'm glad to have you here. My name is five in charge and I will be your instructor for the schools. I am an engineering graduate with close to three years of professional experience on I have been a programmer for close to 10 years now. And if you are someone who is just getting started programming, you have made the right choice by choosing bite on as the language to get started with. And, by the way, say that by Don. It's a pretty simple language for a beginner to get started with. And not just that. Bygone has been gaining a lot of popularity in the field of black and development machine learning data signs in Turn it off things and what not So keep yourself equipped with the basic skills. Have a fight on from which you can advance leave, run on in this girl's I will be giving you just a foundation to get started with Bytom. I have designed the score starting right from the basics. We will be starting on learning the concepts one by one. At the end of each section, you will have notes from which you can go through and you will have a lot of exercise problems which you can practice. We will be solving a lot of programming examples as we progress through and at the end of the goals, you will be working on a project in which you will be implementing all the concepts that you will be learning throughout the schools. Let's go ahead and take a look at our core structure. We will first be starting off with installation and writing your first bite on program. Now, whether you are on a windows or a Mac or a line X machine, I have created separate lectures demonstrating installation for each of them, and you can choose the one that is appropriate for you. At the end of that lecture, you will be writing your first bite on program, which by convention happens to be the hello world problem, and then we dive into concepts such as variables and data types. And then we start with the first data type that his numbers and then we learn about operators. And then we learn about another data type, which is string, and then we head onto sequence which is list Topol and then dictionaries. And this completes the data types and fight on. And now we will move on to conditional statements, loping statements and functions in which we will be manipulating all these data types which we have so far learned. And once you start with conditional statements at the end of each section from here you will be writing complete program and python up until here you will use the Pythons Idol environment to practice all the concepts such as reliable send data types. But starting from conditional statements, you will begin to write by town programs to give you a hands on experience. So after conditional statements, you will learn looping statements and then we head onto functions. Finally, you will implement a project which is to rank top three students off a class. And this project, you will be implementing all the concepts which you will be learning in the schools. No one any point of time you feel you're stuck are you're unable to understand a certain concept. Feel free to use the discussion boat and I'll guide you from there. All right, so I am excited. The next section we will be starting off with the schools, which is to set up your machine. But bite on and write your first program. I'll see you there. Thank you. 2. 2.1 Installation for Windows: Hello and welcome to this lecture. In this lecture, we will be sitting up our development environment on your Windows machine and writing your first program and fight on. Now, if you are a Mac or a line X user, you can skip this lecture. I have created separate lectures demonstrating the installation for a Mac as well as a lay next machine. Now we will be installing Python three as well as a text editor. Now the installation off a text a little is completely optional. You could might as well use the note pad that comes along with your Windows machine, but I personally prefer the interface that the atom editor has to offer, which we will be installing in this lecture. So let's get started by opening our Web Rosa. The one which I use is Google Chrome. Go ahead and open it in your address bar in tow, bite on dot org and scroll down, and you will have an option that saves bite on 3.6. Start one for download, which is the version at the time of creation. Off the scores, click on it and then scrawled on below. You will have an option for a Windows download. So check for the operating system windows and select this executable installer that say's Windows X 86 64 that will make sure that it gets installed on your system with the euro. On a total bit are a 64 bit operating system. Click on it and you don't look should begin, so once you don't know it has been completed. Click on the downloaded executable file on, then your installation off Python should begin. Click Conran on, then click on this check box that says at bite on 3.62 parts to execute your fight on files from command Prompt Now click on install now and that begins your bite on installation. Greater fighter installation has now been completed. Click on close, and now we will go and install our atom editor. To do that on your address bar, enter at M dot io, which should open atoms homepage, and then you will have an option for download for the trouble operating system. That your end, whether it's a torrid orbit, are a 64 bit click on download, and that should begin your download for your acting editor. Download has now been completed. Go ahead and click on the downloaded executable file on that should begin the installation off at a military clique. Conran when prompted. So once you're installation has been successfully completed. You should be on this window off your atom editor. Great. So we now have our fight on as well as the text editor set up on a Windows machine. Let's go ahead and write our first fight on program, which is hello, World. So let me first get rid off all these stabs. No, there are multiple ways in which you can execute a fight on program. We will be sticking on to raise throughout the schools. 1st 1 is to execute it through a text editor and another one is to execute it through Idol environment, which you will be looking at shortly. So you need to use a text editor when you're writing complete fight on programs, which you can execute multiple number of times to write your program. First, open a new file, click on file and the new file and then save this fight as a bite on file. To do that click on file lately can save on. Then you could give any name as per your choice. I will be naming my file as hello world and then ended with an extension dot de vie toe. Identify your file as a fight on file on. Once you do that, you can now start writing your python code. So what we're going to do in this program is to print a string hello world onto your monitor. So in order to do that, python has a function called print. Now, don't worry about these functions and strings all if this will be told in the upcoming sections in the schools. So for now, just type this line of court into your system, which is print and open parenthesis. And then until a pair of double coats and enter the string Hello, Would once you do that saved this fight and executed from a command prompt to do that, open a command from beheading over to start and typing cmd Click on it. No, What you need to do is in the Devi I space the party of file. Now I have saved my file in my desktop so it would be desktop and then give a backslash and filing which is hello world dot Be right now on pressing enter, I will get the output as hello will. So this is one way in which you can execute this problem. Another way is through the bite on idol environment. To do that, click on start and type idol and then click on this executable file. Now this despite on idol environment, which is an interpreter, that gives you output on the flight. So if you want to print hello will in the idle environment, all you have to do is print hello foot and you have your output. So we will be using idol a lot throughout the schools when we need to practice the concepts . As you can see it now, it is really easy to practice concepts using Idol. You just enter the piece of code and you will be able to see the output. But through a text editor, it's a bit off a pain where you need to save the file and then go to your command from and then executed. So we will be using text editor once, well, each the section off conditional statements from where we will begin to write complete bite on programs. So until then, we will be using the idol environment that has been provided by Python. So I will be continuing my execution on my mark machine. But if you have got these two working, which is to be able to execute through a text editor and the Buyten's idol environment, then you should be able to follow along with me. But one important thing that you need to remember. ISS when you execute your fight on program through your command from you need to enter PV right now on my Mac, I will be entering fight on three. But on windows, that command is not recognized on windows. What you need to enter a speed, right? So that's the end of this lecture. You have now set up your development environment on your machine, and you have written your first program and python. If you have faced any issue in this installation, put it up on the discussion boat and I'll help your friend there. The next section we will be diving into concerts and python such as data types and variables. I'll see you there. Thank you 3. 2.2 Installation for Mac OS: Hello and welcome to this lecture. In this lecture, we will be setting up our development environment in a Mac OS. If you're a Windows user or a line X user, you can skip this lecture, have created separate lectures, demonstrating installation for Line X as well as windows, and you can watch whichever is appropriate for you. Now, throughout this course, we will be needing piped on three as well as a text editor. Now you can use any text editor off your choice. You could even use the basic text editor that comes with your Mac. But I personally prefer the interface off the text editor by name Atom. And in this lecture I will be demonstrating how to install Atom as well. So let's start by opening our Broza. The one which I use is Google Chrome and head toe fight on dot org. Now head to the download section and click on which of a version of Fight on three is available at the time off. Recording this video. The version available despite on 3.6 dot one. Go ahead downloaded, and once it is downloaded, click on the installation package. Over here, you can feel free to read through all the license agreements, but I'm just going to hit, continue and click on agree. And if you would like to, you can change your installation directory, but I'm just going to install it in the default directly and just into your admin password when it prompts you to and click on install software. So this might take some time. I did the video here, and I'll get back to you when it is done. All right, So now that our installation has been completed, let's just close this window and you have an option to move your installation package to crash on moving the trash since I no longer needed. And then let's just verify if bite on has been installed. So what we will be using throughout the schools to learn the concepts a spy towns, Idol environment. So in order to check if that has been installed, hit a command space on your Mac and enter I D l E and hit enter. So if this opens up fine, it means spite on has been installed in your computer without any problem. Yes, it does open on. We're good to go with fightin. So next. What we need is a text editor. As I told before, I will be installing Atom in my system. You're free to choose which of a text editor you prefer. So let's once again open of a broza on this time and the atom dot i o And here head over to the download from Mike Option, and once you don't know it has been completed, you will have an option to extract it and editing this video Here. I'll get back to you when the download is done. Great are download has no been completed. Go ahead and click on the downloaded file. Now that should extract your atom package and should give you executable file. No double click it and that should open the atom editor for you. So click on open. Great. So that opened the ad omitted of forests. Now that we have bite on and a text editor installed, let's go ahead and write your first fight on program. Now by convention, the first program that you write in any programming language happens to be the hello world program. So let's write that on our atom editor. So first, save this file as a bite on file. To do that, click on file, head over to save and then enter any filing off your choice on this, naming it as Hello world. Just make sure that you're ending it for the dot b y as the file extension to identify it as a fight on file. Now, in order to write a Hello World program, which is to print the string Hello World on the monitor off your screen, you need a function in python called the Print Function. So in the print and the open parenthesis and enter double codes are single coats and typing . Hello, world. Now all of the's are concepts which we will be dealing lately on strings, functions and all. If it we will be dealing in a lot more detail. But for now, for your first program to be functioning right, just type this into your text editor and save this file now to execute your fight on program, open your terminal. I do that by hitting a command space and then entering terminal, so that opens up the terminal for you. And now what you need to do is enter fight on three space. The part to your filing, which is I have saved my file on desktops, so it will be desktop slash your filing witches. Hello, bull dot levi. And that gives you the output. Hello, world. No, there are multiple ways to execute a python program. We will be using two ways in this course oneness through the text Editor, which you will be using once you reach the section of conditional statements where you'll start writing a programs and fight on. But until then, where you will be executing your python code will be in the idle environment of python. So let's execute the hello world in our idol environment. So command space and enter idol that opens up the idol environment for you and hear what you do is write the string friend hello world and just hit Enter and that should print a string. Hello, Well for you. So now you know why we use item. It's because practicing concepts becomes much more easier. You don't have to go through that pain of saving a file and executing it each and every time. So that's the end of this lecture, you know, have your development environment on your Mac ready. And you have return your first bite on program. The next section is on variables and data types. And from there we will get started with the concepts and python. I'll see you there. Thank you. 4. 2.3 Installation for Linux: Hello and welcome to this lecture. In this lecture, we will be setting up our development environment on a line X machine, and you will be writing a first program and fight on. Now, if you are a Windows or a Mac user, you can skip this lecture. As I have created separate lectures demonstrating the installation for Windows as well as a Mac machine. We will be installing Fight on Three idle environment for python on a text editor. Now the installation for a text editor is completely optional. You could might as well use the text editor that comes along with your linings, but I personally prefer the interface that the atom editor has to offer, which we will be installing in this lecture. So am running this on an open toe machine and we will be performing all installations through command line. So go ahead and open your terminal by pressing control all anti on your keyboard. So once that has been open, entered this command, and that should add a repository into your system. Now, if you are on open to $16.1 are higher version than you can skip this first step, so enter your admin password and hit Enter once again to continue and that should add the repository. So once that has been completed, enter this command pseudo ap ti get a big So what pseudo dust is that? It gives you the super use of privilege to execute that command. And what a pity get up late does is that it updates all your repositories to the latest Russian from the chicken than installed. So once that has been completed into this command pseudo a PT get install bite on 3.6 and that should begin your installation for bite on on this plant PRESTA y and hit Enter. Great. We know. Have bite on 3.6 install in our linings machine. Next, what we will need is the Buyten's ideal environment. In order to install that into this command pseudo a PT get installed idol three. So idol is an environment provided by python where you can execute the python commands. We will be using idol a lot throughout the scores to practice all the concepts which we will be learning. So now we have by country and idle install. Let's go ahead and install the atom. Editor you need to first add a repository, go ahead and entered this command onto your line X machine and press enter press enter once again on prompt and that should add the repository So once that has been completed Next, what you need to do is afraid that repository to the latest washing by running pseudo ap ti get update So once you're update has been completed, you can ignore some off the remesy just that has occurred. That's no problem at all. So go ahead and install pseudo ap ti get installed atom. So we will now be installing our atom editor. Classify on front and click enter. So we have now installed all the tools required for you in the schools. Now let's go ahead and write your first program and pipe down. No, there are multiple raise to write a program and fight on. We will be sticking onto to race. The 1st 1 is to write a complete program through a text editor, which you can than any number of times as you want toe, and another approach would be to run it through the idol environment which were installed earlier. Now idle, we will be using when we need to practice concepts to get immediate results, which you will see when we execute our first program. So in order to do that first, let's execute in our text editor open your atom editor plus your Windows key on the keyboard and enter Atom 80 om and click on the atom. Editor. So this is your item editor in which you will be writing all your python code. So by convention off any programming language, your first program needs to be a hello world program. So let's go ahead and follow the convention and write the Hello World Program and fight on first. What you need to do is to save this file as a fight on file. To do that, click on file, head over to save, and then give any filing off your choice, the final in which I will be using as Hello world. Just make sure that you're ending it with an extension dot provide toe. Identify it as a fight on file, and I will be saving it and my to stop. So once that is done next, what we need to do is to write a function called Print that would print hello World on your monitor. So to do that right print and then open a pair of parenthesis and then a set of double codes are single codes and endless string. Hello, world. Now all of these concepts, which I spoke about no function strings, all of them will be explained much more in detail in the upcoming sections. But for now, to write the first program, just go ahead, write this line of code so that you get the output on your screen as Hello world Now First , save this file and to execute it, you will execute it from your terminal. So go back to your terminal disk. Clear the screen by typing clear and then to execute it. Type Eitan three Space your file name. So before that, give the location for your file. Like how I showed you earlier. I had saved it on my desktop so it would be desktop slash hello world dot every I and there we have our output. Hello, would. So the next execution, which we will be doing, is through the idol environment to open that hit the windows key again and enter I D, l E and click on Idol three now in your Idol tree. All that you got to do is to enter print and then hello, but and on pressing enter, you get the output right on the screen, and this is the reason why we will be using Idol a lot throughout the scores. The practicing off concepts becomes really, really simple. So that's the end of this lecture. You have your development environment now ready. I will be continuing execution on my Mac. But if you have got the Easter programs working, then you should be able to follow along with me. If you have faced any issues during the installation, use the discussion boat and I'll help you from there. So you now have written your first fight on program. Let's dive into concepts into our next section, which is variables and data types. I'll see you there. Thank you. 5. 3.1 What is a variable and how to define one: Hello and welcome to this lecture. You have now set up your development environment on which of a system urine. You wrote the first program in Python. And now let's dive right into learning the contents off by Tom Programming. So the first concept, which we will be discussing about on which is the topic off this section, is variables. In this section, we will be learning water variables. How to define variable on the rules you need to remember while defining available. So let's start with what is a variable to go. By the definition, variables are reserved memory locations that I used to store values on a reference by name . Now that definition could be a bit confusing at the beginning. Don't worry. Let's take a look at that. With the help of an example, take the card act application off phone. How does that work? Say, for example, you need to store the contact number off your friend named John. How would you do that? You enter John's contact number on your phone and you save it under the contact named John , and any time really John's contact number, All they would do is look up on the contact named John, and that would give you his contact number. So that's exactly how variables work. You assign values to valuables, which you can use at any point of time in your problem. Now, let's go ahead and take a look at how to define a valuable to learn how variables work. Let us start by first opening the Idol environment off fightin on my Mac. I do that by hitting a common space and entering Idol. Now that we have idle open, let's take a look at the syntax to define a variable. This syntax to define a variable is valuable. Name an assignment operator on the value? No, what an assignment operator does is it assigns the value at the right hand side to the valuable at the left hand side. We will be discussing more about operators and detail in the upcoming sections. But for now, just remember how the assignment operated works. Also, you can see here that I have started the statement for the pound symbol, which means it is a comment and not a part of my python code. Now to take an example off a valuable name, let me consider the total marks scored by a student. See, for example, a student has secured 95 assess total marks. So how do I define a valuable for that? Let me first give a variable name, which will be total marks equals the value off that variable, which is 95 now at any point of time in your program, when you refer to the variable total marks, the value returned has to be 95. Let's print total marks and see if it works as expected. There the value being returned its 95 ah thing to remember about variables as variables can be changed at any point of time. The value 95 being held by total marks can be changed at any point of time in your program . If I change it to 100 then if I print total marks, as you must have probably guessed, the value is 100. Another thing that I would encourage you all do is to follow certain naming conventions while defining variables. The naming convention, which have used here a Scammell casing where in my first letter starts with a lower case and subsequent words. First letter starts with an upper case also used meaningful variable names such as the one which we have used in this example refrain from using variable names such as a equals 200 knows. Though this isn't tactically right, this absolutely makes no sense to the reader off your program, so make sure that you use meaningful variable names. So that's the end of this lecture. You learned water variables how to define a variable In the upcoming section. We will be discussing about the rules to define a valuable. And I'll see you there. Thank you. 6. 3.2 Rules to define a variable: Hello and welcome to this lecture on Lulu's to define a variable In the previous lecture, you learned how to define a valuable Let us further and Hansel knowledge by getting to know the different rules you need to remember while defining a valuable there are majorly four rules you need to remember, and we will be discussing each of them in detail. Rule number one, Your variable name Should I to start with an alphabet or an underscore, followed by any number off alphabets. Numbers are under schools, so from the previous example, total marks equals 95. This is a valid declaration as my variable name starts with an alphabet. Now another really blame which I can have this underscore. Total marks 123 equals 200. Now this valuable name starts with an underscore and has a combination off alphabets and numbers, which is perfectly fine and should not throw me and yellow. But if I go against rule number one and start my valuable declaration with the digit, this should result in a never as it goes against rule number one Zululand. Batou sees variable names are case sensitive. Now what does that mean? I could have a valuable name. Total marks equals 95. I could also have another value. Blame off the same name. Total marks differing by case In this case, I have given Total March starting with an uppercase T on this is a valid declaration on it is an entirely different reliable from the previous one. Let's verify that by printing both our valuables. If I print total marks with a smaller Casey, it returns 95. And if I print total marks with the uppercase T, it returns 100 blue number three C's resolved names cannot be variable names, no water result. Ning's resolve Names are certain keywords on the names off inbuilt function specific to a programming language that cannot be used. So one result name, which we have been constantly looking at, is the print reserved. Would print is an anvil function and bite on that has a specific purpose to print whatever you mention in it. Another example for a keyboard is the four Give Word, which we will be looking in the upcoming section, which is a loping statement. Now if I try to use for as my valuable name, this should throw me another as it goes against the rule there. The final rule is the only special character allowed in a variable name is the Underscore character. No water special characters. Special characters are characters apart from alphabets and numbers. Some off the examples are the dollar sign the pound sign the underscored etcetera. For example, if I have my valuable name, Total marks with a dollar sign at the end, this should not let me create this variable there. It results in an invalid syntax, as the dollar sign is a special character and I cannot go any further. So that's the end of this lecture. Make sure that you remember all these rules while defining a valuable. In the next lecture, we will briefly discuss about the different data types available and python. And I'll see you there. Thank you. 7. 3.3 Data Types: Hello and welcome to this lecture. Now that you know what are variables, let's take a look at the different types of valuables or also called as the day that types , which we haven't python invite on. The data types are classified into five major categories, and they are numbers. Strengths lists troubles on dictionaries. In the upcoming sections, we will be discussing about each of them in much more detail. Now let's take a quick review on what we have learned in the section on valuables. We started the section by discussing about what our valuables, they are reserved memory locations that I used store values and our reference by a name on . Then we checked how to define a variable. You need to have a variable name, followed by an assignment operator and then a value, which you will be assigning to your valuable. So in this example, we're assigning the value Sunday to the variable day, and then we check the different rules to define a variable that a four rules you need to remember. Rule number vine is a valuable name should either begin with an alphabet or an underscore. Rule number two valuable names are case sensitive, which means you can have two variables off the same name, provided they differ by case. Rule number three Valuable name cannot be reserved name. Now. Reserve names are key vote such as far if, while etcetera, which we will be discussing in the upcoming sections on the final rule you need to remember , is that the only special character allowed to be a part off your variable names is the underscore character, so you cannot have characters such as the doll Assemble the pound symbol are any special character for that matter? And finally, we briefly looked at the different data types available in fighter. Their numbers string less trouble and dictionary. So that's the end of review. On the section on variables and data types I have attached PdF notes and exercise problems for practice. Go through all of them. In case you're stark, feel free to use the discussion boat and Al Qaeda from there. The next section is on numbers where you will be learning how to handle numbers and fight on on dsi You there. Thank you 8. 4. Numbers: Hello and welcome to the section on numbers in this section. People discussing about border numbers, the different types of numbers and bite on on how to come up with a number from one type to another. So what are numbers, numbers and arithmetic values that I used for mathematical purposes suggests counting, measuring are making some calculations at separate. So let's now take a look at how to implement numbers and by Let us now open pythons, Idol, environment and get started with implementing numbers. Numbers are of two types, one as the non decimal or the indigent amble, and the other is the decimal or a floating point number. Let's see what they are. I'll be declaring an anti gin number with the Value 10 which is a known decimal number, and I'll be declaring a floating point number with the value 20.75 If a print these variables, it should return the value stored in these variables. So on printing floating number, it returned 20.75 Similarly, on printing in teacher number, it returns stent. Now, if you would like to check the data type off the Israeli, a bles bite on comes with the function called type No functions as something which we haven't discussed at this point of time. But for now, just understand that types checks the data type off a valuable And how do we do that perent Call the type function and which variable name data type do you want to check? So that name you pass it in parenthesis, which is floating number. So as you can see, the output is class float, which means my variable floating number ISS off type float. Now, if you would like to convert available from one data type to another, there is a concept called typecasting. So what typecasting does is it takes a variable and convert certain toe another variable off your choice. So let me convert my floating number into an integer number so floating number is going to be converted into an impeachment number. I first need to mention what type I want my variable to be converted to. In this case, I wanted to be converted to type in teacher. In short, it is called imp on. Then I passed the valuable name riches floating number. Now, if you print the type off the floating number it should be off typing teacher. Yes, it is. But then what happens if you print the value store of the floating number? What do you think the value would be now? Most off. You might think that since 0.75 lace beyond 0.5. Mathematically, my output has to be 21. But does typecasting work that way? Let's find it out. Well, the output is 20 which means typecasting ignores the decimal part off your number. It only re pains the integer part if it which is 20. So that's the end of this section. You learned the different types of numbers you learned how to print the type off a number and how to convert a number from one type to another. Do go through the pdf notes attached with the section and solve all the excites problems. Next section is about operators. Well, we will be playing around a lot with numbers and I'll see you there. Thank you. 9. 5.1 What are operators ?: Hello and welcome to the section on operators In this section, we will be discussing war our operators, the different types of operators on their implementation and python. In this lecture, we will briefly discuss about border operators and their different types. So what are operators and operator is used to perform an operation between two operates. So what does that mean? Take for example. In addition, operation between the numbers two and five here, the numbers two and five are called operates on the addition. The place symbol, which you use is called the addition operator. So once you perform an addition operation on the operations two and five, the result being written will be set. So what are the different types off operators and fight on? The different types of operators are assignment operator, arithmetic, operator, relational operators and, finally, logical operators. So what is an assignment operator now? A sign the dark reader is something which we have seen in our previous lectures. When we learned variables, we assign a value toe available now when you assign a value, what you made yourself was an assignment operator, which is the equal to operator next. What we have is the arithmetic operators. So we have five arithmetic operations which can be performed. Their addition Subtraction Multiplication division on Modelo operations. Next, what we have is the relational operators. Now, relational readers are compound within operators. Now, this is something which we do in our day to day life. Say, for example, you're buying a new phone. So what do you do? You take two phones which you will be comparing the specifications off and then you check if the memory off this phone is greater than the memory off the other four. So for such purposes, we make use off the relational operators. Next, What we have is the logical operators, which is a combination off relational operators. Which means, say, for example, you're checking the operating system off your phone. So you want to check if the operating system is I hope s and it has a cabin off 12 mega fixes on one more thing. What you can do with the logical operators is the our operation, which is to check if one among the conditions that true, so for and operation, what you did was to check if both the conditions were true, which is to check if the operating system is us and your camera is 12 megapixel only then you would buy the phone now in the art operation. What you would do is check if von among the two is okay for you. So you would check if my operating system is a U. S or my camera is a 12 megapixel camera. So if one off these two conditions holds good that I will go ahead and buy this phone. So that's the end of this lecture. In the next lecture, we will be implementing all of these different types off operators in Python and see you there. Thank you. 10. 5.2 Different types of operators: Hello and welcome to this lecture. In the previous lecture, V briefly discussed about the different types of operators on in this lecture. We will be diving into each of them and detail. Let's start by opening vitamins Idol Environment. The first operator, which will be starting with, is the assignment operator. Now the assignment operator is the equal tow operator, which we have seen a lot of times before. It assigns the value at the right hand side to the variable at the left hand side. Now, if we take the example which we had taken at the beginning off the previous sections, Total marks code by a student equals 95 which means the value 95 is being assigned to the variable total marks. So if I print total marks, it should print the value that it was assigned with, which is 95. The next operator, which we will be talking about, is the arithmetic operator. No arithmetic operators are five types. Firstly, addition operator, then subtraction, then multiplication, then division. And finally the module. Oh, operator, let us take a look at each of them. The firstly, the addition operator when I say two plus two less is the addition operator, which adds the value at both the left hand side on the value at the right hand side and gives the result full. Next up is the subtraction operate. Um, if I say 10 minus eight minus sign is the operators for subtraction. It subtracts the value eight from 10 and returns. The value to next is the multiplication operate um, which is denoted by a star symbol. If I say four star food, it returns the value 16 which is four times full. And then comes the division operator. If I say 10 forward slash five forward Slash is the operator denoted as the division operator, it returns the caution to now. As you can see, it returns the value 2.0, which means by default precaution is being converted to float Now for some reason, if you didn't, if you do not want that to happen, if you want your caution to remain in teacher intact is what you can do is give a double slash 10 double slash five and dad will return the value, too. And finally, in the arithmetic operator, we have the modular operator, which is the remainder off a division. If I say 15 more. 10. The person eight symbol is used to denote the modular operator. It returns the remainder off the division, which is five. The next section off operators is the relational operator, and they are off six types. First is the less than operator. Then comes the less than are equal to then comes greater than than the greater than or equal to than the double equal to and finally the nautical to. So what do they do less than operator checks if the value of the left hand side is less than the value? What the right hand side, for example, if I say to is less than five, it is true, since two is less than five. What if I say five less than five now? Five is equal to five, so this should return false. Now the next operator is the less than are equal to operate. So what does that do if I say five less than or equal to five. It first checks if five less than five Now, since five is not less than five, it next checks of five is equal to five. No since five is equal to five. It returns true, No water if I was checking for the condition. Six is less than or equal to five. Now, with first Texas, if six is less than five, since six is not less than five, then checks if six is equal to five. And since that is not true as well, it returns the value. False Next operator is the greater than operator and a true, and it works in the exact opposite way as that off the less than operator. If I say five greater than two, it returns. True, if I say to greater than five, it will return. False. Next up is the greater than or equal to operate Um, which is the opposite off, less than or equal to operator. If I say a five, if five is greater than or equal to five, it first checks. A five is greater than five, since five is not greater than five. It then checks if five is equal to five, which is true if I see a five is greater than or equal to 65 it's not greater than six and five is not equal to six, and hence the value falls. Next up is the double equal to riches. A comparison statement. It's it is used to check if the value at the left hand side is equal to the value at the right hand side. If I say five double equal to five, it should return through, since five is equal to five now, the reason why a double equal to is used is to differentiate it from an assignment operator , which is a single equal to now. If I say to double equal to five, it returns false. And finally we have the not equal to which is the opposite off equal to if a safe five nautical to five, it returns falls since five is equal to five. And if I say to not equal to five, it returns the value true. And this it's how you denote, not equal to and exclamatory mark with an equal to symbol. Next up is the logical operator. No logical operators, our operators whose execution depends on the result off certain conditions that are three logical operators. They are and are and not. Let's see what each of them do. The and operator Onda operator requires both the conditions at the left hand side off and as well as the condition at the right hand side of the ant to be true. For example, if I say to, it's less than five. Andi five is less than 10 here and making sure that both the statements are true. Only if both these statements are true will I get the answer as true now, if I have to do is less than five and five is greater than 10. As you can see, five is not greater than 10 and this should give me false. So for an and operation toe work, both the conditions should return True. If von among them returns and falls, my answer would be false. The next operator is the or operator. No word and are operated does is it needs one off the two conditions to be true, either the condition on the left or the condition of the right. Let's take a look at an example if I say to was less than five. All five is less than 10. No, both to is less than five as well as five is less than 10 so this should return true if I see five is greater than 10 or two was less than five. No. Five is not greater than 10. I'm checking if do was less than five. No file is not less than 10 but do is less than five on this will return true, since the second condition was true. And finally we have the not operation, not operation reverses the output. For example, when I say to greater than five, it returns false. If I say not off do greater than five, it reverses the output from fall. It's too true now. That's a lot of information. And once rich, let's take a quick review off what we have learned. We started the section by discussing about what is an operator. An operator is used to perform an operation between two operations, and then we looked at the different types of operators. The 1st 1 which we looked into was the Assignment Operator, which is the equal to operator, and it is used to assign a value toe variable. In this example, the Value 100 is being assigned to the valuable total marks. Next, what we saw was arithmetic operators, so we have five different types of arithmetic operations first is the addition operation, which is used to add to operates the next of the subtraction operation which returns the difference between two operates Thought is the multiplication operation which is used to return the product off the opulence. Fourth is the division operation which returns the caution off a division performed and finally we have the modular operator which returns the remainder off division performed in this example the dividing 97 by 10 and the remainder seven will be returned. Next. What we saw with relational operators now relational operators return Boolean value as the output. No Boolean values can either be true are they can be false So we have equal to as a relational operator which is identified by a double equal to in order to different shaded from an assignment operator. So what we're doing in this example is we check if do is equal to which is true and then we check the next relational operator, which is the greater than operator. So in this, what you do is you check with the one operative in the left hand side is greater than the operate in the right hand side. Then what we saw was the lesser than operator in which we check if the opulent at the left hand side. It's less than the operator at the right hand side, in case it is less it pretends true. In this case, 10 is not less than five. Because of Fitch returns, the value falls next. What we saw was the greater than are equal to operator, which returns true if the value at the left hand side is greater than are equal to the value at the right hand side. In this example, we check 15 is greater than or equal to 15. So what Fight on checks is first, if 15 is greater than 15. No, that's not true. Then it checks. A 15 is equal to 15 which is true because of which it returns the output as true. Then what we saw was the lesser than or equal to operator, which is the opposite off, greater than or equal to operator. So if the operator of the left hand side us less than are equal to the operator of the right hand side, it returns the value true else returns, the value falls. Then what we check was not equal to which is the opposite Off the double, equal to operator it returns true if the operating at the left hand side is not equal to the operator at the right and say finally what we check was the logical operators which are and are not no logical operators on checks, multiple conditions. It needs both the conditions to be true. In order for the output to be true. For example, we had made a check if to was less than five, which is true. And then you check if 10 is greater than seven which is also true because of which returned the value true Now if the first condition had failed, if you was not less than five, saving had given a condition to greater than five. In that case, the first condition itself was false and the execution would not have continued further. Next, what we saw was the our operator. Now our operator needs one off the two conditions to be true. In this example, the first check, if do, is greater than five, which is false. So know what we do is we check if the second condition is true. The second condition is five is greater than are equal to fight, which is true because of which the output off our our is true. Finally, what we saw was not operator, which reverses the output. So in this example, we check if 10 is greater than five, which is true. And since you're adding and not operator, it reverses the output and gives you the output that's falls. So that's the end off review on the section on operators. The next section is on strings. You have already started using strings, but in the next section you will learn a lot more about it as always, referred to the notes and exercise problems attached in case your stock used the discussion boot. I'll see you in the next section. Thank you. 11. 6.1 What is a string and how to define one ?: Hello and welcome to the section on strings. In this section, you will be learning water system, how to create access and modify string and some off the operations that can be performed on the street. So what is this place? String is a sequence of characters that are enclosed within single audible coats. Now what is a character? Characters could be just about anything. It could be an alphabet. It could be a number, or it could also be special characters. Especially characters are characters such as the dollar, simple, the pound symbol and so on. So any character enclosed within a single or double codes, it's called a strength. Now let's go ahead and implement strings and fight on. Let's get started by opening Pythons Idol environment. So what does the syntax to the finest ring? The string is defined within a pair off double coats or single coats, so my syntax would look like a string variable, an assignment operator and my string in a pair off double coats. Or I could also have it in a pair off single coats. No, no, that this statement has started with the pound symbol, which means it is a comment and not a part of my coat. So to take an example, let's say I want to stole the name off a fruit. So I have my variable name fruit and my string name within a pair off double coats. And then at any point of time when I see the value, or rather the valuable fruit, it should return to me. The name off the fruit, which is apple strings, are stolen as a sequence of characters and each characterless accessed by what we call as an index. Let's see what that is now. This string, which we have Apple, is stolen as a sequence of characters as a P. P l E. And each character is associated with an index value starting from zero, which means the first character a has the index value. Zero. The next character, P has an index value one, and so on. The final index value would be the length off the string minus one. The length of the string is nothing but the number of characters off festering. So in this spring, I have a P p l E, which is five on the last character off. Miss String would have the index value and minus one, which is five minus one for So if I say the character at the index position four, that should written 01234 the value e Now let's see how that works. So I give the name off my variable, which is fruit on. Then the index is specified within a pair off square brackets. So within a pair of square brackets, I enter the index value. Say I need the first character. So I give the index position zero. So that should return A. And similarly, to get the last character I give the last position, which is four. And it gives me e No. What if I interliant value that is beyond the range? Well, that would definitely result in a syntax. Elop, Let's check what that terrorists. So if I define if I to find beyond the range off 0 to 4, that would give me a string index out of range. No, Like positive in this is you also have negative in this is no. When you start counting from zero, it starts the con from beginning off the string. But when you start with negative index, it starts counting from the end of the string. So as we saw fruit off four returns, the value e Another way to access the last character is to have a negative index. So if I say fruit and if I specify the index value as minus one, it would return the last character off my string, which is e Similarly, If I enter fruit and minus two, it would return the value L, which is the last second character now, a common problem that you might come across while defining a string nous the usage off single coat or double coat. You know what if you wanted to have the string called String is one among by thons data types. No, the apostrophe as a part of your string. Let's see how that is being created when you define a string in python. So I have my string name. Let me discolored string and I enter the string within a pair off single coats so that would be string as one among by tones, data types. Now let's see what happens. So what happened in the string? Waas Though apostrophe was supposed to be a part of us string the special property off the single coat has ended the string than to consider it as a part of a string. So our string has been considered as string as one among python and the rest if it was just discarded. So how do we overcome this problem? We have two ways in which we can overcome this problem. The first way is to use a double coat instead off a single coat. Let's see how that works. So that would be start mystery in with a double coat and then continue mustering as it is. So what happens in this case is, since you have started your string with the double coat bite on, would look for another double coat toe. End the string now, since the part of his string is a single coat that does not end a string there. Instead, it ends the string when it finds a double coat. So now when you print a string, it should work just fine. No, what if you wanted to start your string with a single coat and not a double court, but still use that apostrophe as a part of your string? In that case, we use a mechanism called escaping. Let's see what that does. So I start my string with a single coat. And then what I will do now is to escape the special property off the single coat. The special property off a single coat and python is to start our industry. What we will be doing now is to escape that property and treated as a single coat itself and are the special property. So in order to do that just before you enter your single court, you enter a backslash and then enter your single coat. So what happens when you enter a backslash is it does not treat the character after the backslash as a special character. Instead, it just treats it as a normal character. And then I continue with the rest of my string. Now I ended with a single coat and now when I print my string, it should work just fine, which is string is one among pythons data types. I missed out typing in s. But as you can see, the single coat has bean taken as a party festering without any trouble. Next, what we will be looking at is the string formatting in python to understand what that is. Let's go ahead and print the string. Let's say I have a string bite on Is a great programming language for bigness. No, What I you want to do is replace. This would fight on with the variable. I want my piped on to be stored in a variable and that variable name should be a part of my string. So in order to do that, let me first create a valuable called programming language and store the value pie tone in it. So on printing programming language I know have a fight on and no, whatever be doing is replaced. The would fight on in my string with programming language. So in order to do that, I go ahead and enter the name off my valuable, which is programming language and then continue with the rest of my strength. No. What? We want our output here to be Yes, the programming language needs to be replaced by python, and output has to be bite on is a great programming language for bigness. But what happens is the programming language has been considered as a part of festering on . It was printed as it is no. What do we do when we want to include a variable name as part of a string? That's where string formatting comes into picture. So if I need to do that, what I should be doing is to enter a pair off Kohli braces, which will be a placeholder for my variable name programming language and then enter the rest of my string. Next, what I will do is have a dot format and then enter the name off your variable, which is programming language. So what this will do is the curly brace, which you had used as a placeholder for your variable name. The variably mentioned in your format function will go and that place now on execution off this, we get the output by down as a great programming language for bigness said. That's how string formatting works in pipeline. No, to understand how to modify a string, it's pretty simple. Let's go back to our previous ring fruit, which has the value apple. Now, if you want to modify the string, all you have to do is have an assignment operator and change its values. Say I change it to mango. No, on printing fruit the previous value has been modified to mango. So that's the end of this lecture. You learned how to create access and modify Yes, string. And you also learned the string formatting and python. In the next lecture, we will be learning about the different operations that can be performed on strings. I'll see you there. Thank you. 12. 6.2 String Operations: Hello and welcome to this lecture. In the previous lecture, you learned how to create a string. And in this lecture you will be learning some off the operations that can be performed on a string. I have my Pythons idol environment open and I have created a string which is by town. Programming is easy now what? We will be doing this. We will be using this string throughout this lecture on which we will be performing operations on. So to get started with the first operation, which we will be looking at, is the string dart upper operation. Now what string that upper does is it converts all the characters off your string to uppercase characters. Now to see how that works, let's go ahead and until a string and then use a dart upper on it. So what that would return is all the characters off a string in upper case characters. No similar toe upper. We also have a function called string dot lower. No, As you might have probably guessed, What this will do is convert all the characters into lower case characters. Now, when I executed bite on programming, it's easy and it's all in lower case characters. This time the next operation which we will be looking at, is the replace operation. So what please operation does is it replaces apart off your string with another string. So to demonstrate how that works, let's go ahead and replace the vote easy with the word powerful. So to do that string daughter place and I want to replace the word easy so that would go in first and separated with the comma and then entered those string powerful no, on execution. Off this, you can see that the string are rather than what easy has been replaced with buffalo. The next operation which we will be looking at, is the slice operation. Know what slice operation does is it slices your string into a shortest ring Now what if I wanted just the first word off my string so I can perform a slicing and get that first word out of my string? To do that in, take a string name and then within a pair off square brackets, what you should do is give the starting index off where you need the slice to start from now. I need my slice to start from zero, which is the index value off beat and then enter the ending index on just before that, you need to enter a colon which acts as a separator between the starting and the ending index. So you're ending Index would be be vital. Hetch o n There are six characters which means the value off are the index value. Off end would be five. But make sure that you give one more than the index value. Now, since the index value off endless five, I should be giving here as six know When I do this, I get the output as python. So that's how you perform a slice on a string. The final operation which we will be looking at is the length operation. So what linked operation does is it computes the number off characters off your string and returns the individual output to you. So to see how that works, you call the Lin function and then you pass the name off your string, which is string no, on execution. Off this, you get the output as 26. Now, Len is a function functions as something which we haven't discussed at this point of time. But for now, all you need to remember is Len is a function that returns. The number of characters are festering. Functions will be dealt in a lot more detail in the upcoming sections. Just remember that Bite On has a lot of Finn bill functions, and Len is one among them, which is used to compute the length off your string. So that's the end off this section on strings. Let's take a quick review on what you have learned in the section. We started the section by talking about What is a string, which is a sequence of characters enclosed within a pair of single codes are double coats, and then we check how to define a string. You have a variable name, followed by an assignment operator, and you assign a string toe available, and then we check it some off the string operations. We have our example spring as welcome message that reads, Welcome to this introduction. Calls on Fight on programming. Hope you're having a good time learning. So the first operation, which re performed on destroying Waas, the upper operation in which all the characters off the string were converted to uppercase characters And then what we saw was the lower function, which is the opposite off the upper function. It converts all the characters of history to lower case characters. Then we saw the replace function, which is used to replace a part off your string with another string. So in this example, we replaced the word learning with experimenting and I'll string, then returned the final sentence as hope you're having a good time experimenting instead of the string. Hope you're having a good time learning. Then we saw what the string slicing. It returns a slice off. Yesterday, based on indices bust, we checked how to retrieve values using the index position. On that end, exposition will be passed for slicing a string. So we have this example in which we're slicing the string from the index 0 to 7. Now the ending index of seven the value which the fight on will take will be ending index minus one, which is six. So all the characters from the index position 0 to 6 will be sliced and returned to you, which is our output. Welcome. Finally, what we saw was the length off the string. We have a function called L E N, which went past with the string name returns the length off that string. And after spring operations, what we saw was how to format a string. So what a string formatting you can use a valuable lean as part of a string. And how do you do that? You make use off a placeholder, which is a pair of curly braces, and then you ended with the dot format and enter the valuable name. So in this example, we have a valuable called programming language, which has the value string in spite on on in our friend statement via placing a placeholder for the programming language and in the dark format, we're passing the valuable name programming language. So the final output off this ring would be welcome to fight on programming. The Kali braces will be replaced by the valuable in programming language, which in turn would be replaced with its value by. So that's the end of review. On the section off strings go through all the notes and exercise problems and use the discussion board if you need my help. So the next section is on lists and I'll see you there. Thank you 13. 7.1 What is a list and how to create one ?: Hello and welcome to the section on list In this section, you will be learning what is a list? The need to go for a list. The implementation off a list in Beit on on some off the operations that can be performed on a list. So what is the need to go for a list as you You're a teacher off a classroom, and you need to maintain a record that holds the names of all your students so say you have 30 students in your class. So in order to store their names off 30 students, you will have to create 30 variables. Now what if you had 1000 students, you would have had to create 1000 valuables, which could be pretty tired. Now the list is used to eliminate such problems. Unless is a container, which is used to store a collection off objects, which can be accessed by a single name on in order to access each student in a list. We do that by mentioning the index position off that student. Now let's go ahead and implement a list and fight on. Let's go ahead and open pythons, Idol environment and get started that learning how to implemented list the syntax. To define a list is to have a list name and the objects off a list within a bear off square brackets, so I could have object. One object to object three and so on. For example, say you want to create a list off your favorite fruits. How do you do that? I create a list called Favorite Fruits and assign it with values. Apple Manigault on Finally Strawberry. Now, if I print my list, it should return the list apple, mango and strawberry. Now to access the values from a list we use indexing in case you must the lecturer on indexing from the section strings Indexing is usedto retrieve values from a list or a string. Indexing starts with the value zero, which means the first element off my list has an index value. Zero. The second element has an index value, one the third element and index value to and so on. So if I wanted to print the first element off my list favorite fruits, I would say favorite fruits. The index value within a pair of square bracket, which is zero for apple Now. If I wanted the Prince strawberry, I would say favorite fruits. The index value for strawberry is too. And hence I mentioned the value, too. So I get the output as strawberry. Now, let's see how to modify your list. Say, for some reason, you say mango is no longer your favorite fruit. You would like to replace it with orange. What do you do then? You modify your list by entering the name off your list on the index off the fruit, which you want to replace. No mango has an index value. One on you mentioned the value one. You assign it with the new value orange. And now when you print your list, you get the value apple, orange and strawberry. The value off mango has been replaced with orange. That's the end of this lecture. You learned how to create a list, how to access a list using index and how to modify a list. The next lecture we will be discussing really ist list operations, which we can perform and I'll see you there. Thank you 14. 7.2 List operations: Hello and welcome to this lecture. In the previous lecture you learned how to create a list. And in this lecture you will be learning about the different operations that can be performed on a list. I have pythons, idol, environment open and I have our example from a previous like job which is the favorite fruits example for the values apple origin Strawberry. The first operation which we will be discussing is the upend operation. So what an up and operation does is it lets you add an element at the end off the list. Say, for example, you wanted to add another fruit to this list. Say Kivi. So how do you do that? Favorite fruits dot upend and then you enter the name off the fruit which is Kivi on printing this you get the output off apple or in Strawberry and Kivi, which has been added at the end off your list. The next operation, which we will be looking at, is the insert operation. Do you remember the mango fruit which he earlier got rid off? Now what if you've had that love to its mango and you wanted back in the same position so In that case, you can use the insert operation very mentioned the index position. Very want to insert the fruit and then the name off the fruit. So I want mango to be inserted at the index. Position one Now on printing this, I get the output. Apple mango are in strawberry and Kivi. As you can see, mango has been inserted at the index position one, the next operation which we will be looking at this list dot removed. So what remove operation does is it lets you remove any value which you mentioned in parenthesis. So how do you do that? You enter the name off the list dot Rameau and in parenthesis you get rid off the fruit, which you no longer want. Let me get rid of strawberry this time. Now on printing the favorite fruits lest it gives you the output without strawberry, the next operation which we will be looking at is the salt operation. So what sort operation does is it arranges your less deny the Ralph A particularly all numerically depending on the content off your list. So if I implement assault on my favorite flutes list, let's see what happens as you can see, since the alphabet K off TV is before M and oh, alphabetically, the order off TV has changed on my list has now been salted alphabetically. The next operation is the reverse operation. So what Rivers operation does is it arranges the order off your list in the reverse order. Let's see how that works on our favorite fruits list. Let me print it there. The order off my list Previously was apple caving mango and orange on reversing my list. It is now orange mango Kivi an apple, which is the reverse off my older list. The final operation, which we will be discussing about, is the pop operation. Know what a pop operation does is it fetches the last element off your list and it returns that element to you. And also it deletes that element from the list. So if we implemented on our favorite fruits list, let's see what happens. So as you can see, it has returned the last element off my list, which is apple. Now. If I print my favorite fruits list, my list now does not contain Apple. That's the end off this lecture and the section Let's take a quick review about what we learned in the section off lists. We started the section by talking about water listers, unless it's a container that holds many objects under a single name. And then we saw how to define a list. You need to have a variable name, followed by an assignment operator on your objects enclosed within a pair of square brackets. Now we have an example list, which is best friends, and it has the elements Mark, Mary, Maria and John, which are separated by comma. And then we saw how to access values in a list. Each value in a list is identified by an index position starting from zero. So the first element in your list has index position zero the second element with the index portion one and so on. So, in our example, best friends. When used with an index position of zero, it returns the value mark, and then we saw some off the list operations. The first operation, which we saw was the upend operation. The upend operation is used to add an element at the end off your list, so you use the name off your list with the dot upenn function and you mentioned an element which you want to add at the end off your list. So in this case, it is best friends dot happened with the name Matthew. A list is now appended at the end with the matter and then what we saw was to insert on element into your list. Now what if you don't want to upend into your list, which means to say what if you don't want to add at the end off your list, but somewhere in between your list. In that case, you use the insert function very past the index position on the element to be added. No, the past the index position one on the element has been. So our list now has been at index portion one. Then what we saw was the remove operation, which is used to remove an element from the list. So in our example, best friends we used dark removed with the element merry, so merry is no longer a part of our list. Then what we saw was the sort operation which is used to sort your list alphabetically. So if you use the sort on best friends, it sort it alphabetically, with Ben starting at the beginning, off your list and mark at the end off your list, all sorted in alphabetical order. And then we saw the reverse operation, which is used to reverse a list. So if you call your list with the reverse operation, the order off your list gets reversed. So we now have mark at the beginning offer list. And then at the end of her list, then we saw the pop operation, which is used to remove the last element from your list. And it also returns that element to you. So if you use it But best friends dark pop, you get, the output has been on. Also, Ben gets removed from the end of the list. So that's the end off this section on list. Go through all the notes and exercise problems, practice all of them. If you have any doubts or if you're stuck and you need help, feel free to use the discussion boat, and I'll help you from there. The next section is on topples and I'll see you there. Thank you 15. 8. What is a tuple and how to create one ?: Hello and welcome to the section on Triples. In the section you will be learning what is a triple the need to go for a tipple. How to implement a tipple in Beit on and how to delete a couple. So to start with what is a couple? A couple is a collection off immutable objects. Now you might ask me What is this term called Immutable and collection off optics list already does that for me. Then why should I go for a tipple? Let's get these dots clarified with help off an example. If you can recall, we had taken an example in the section off lists in which we stored the names off students off your class. Let's take a similar example. But this time, incidents during the name we will be stolen their date off book. Now you can use a list to store the data both of students. But list is something that can be modified. No data. Both is something that is not meant to be changed your data, but is not going to change no matter what. But list lets you modify the contents in a list that does the need to go for a triple double. Makes sure that a couple once defined cannot be modified or any part of your problem. So when you want to store value such as state off, both, which you know for sure are not going to change in such cases, you should be using a tipple. No, with this understanding, let's go ahead and implement trouble and fight on. Let's get started by opening Pythons Idol environment The syntax to define a tipple is to have a couple name an assignment operator and the objects off triple enclosed in a pair off parenthesis. The Declaration of Fotopoulos similar to that off list. The only difference is that the objects are enclosed within parenthesis. Vera's and list. They were enclosed within square brackets. Now let me create a Topol to stole. The start dates off World War One and two to pull to store. Start dates off World War One and World War two. No, you do get to know the reason why we're choosing a triple, don't you? It's because these are historic dates on. They're not meant to change. And that's the exact property off a couple. So let me call my two Poulos historic wall dates and assign it. But the start date of World War One, which is 1914 and the start date of World War Two, which is 1939 now to access the value off a triple it is similar to that of lest you just mentioned the index off your object. So if I wanted the date of Old World One, I would call my historic walled eight stupor with the Index zero Index are to be enclosed within square brackets on that returns 1914. Now here. What if I try to change the date off World War two? If I tried to do that, let's see what happens. My World War Two is told that the Index one and if I change that to, say, 2017 what happens? I made a type of right here. It is historic world. It's so what happens now is to pull. Object does not suffered item assignment, and this is where Topol differs from a list. A list lets you modify its contents, whereas a couple does not let you do that. No, let's see how to delete. A triple bite on comes with a function called the L, which stands for delete on Within parenthesis. You mentioned the name off the Topol, which you want to be deleted. So historic wall date is the triple, which I want to delete now. If I tried to print historic wall dates, let's see what happens. Name, Historic world. It is not defined. Which means my Topol has Beene deleted and can no longer be accessed. That's the end off this section. You learned water topples. You learned how to create a trouble on you. Learned how to access and deleted triple. The next section is on dictionaries and I'll see you there. Thank you. 16. 9.1 What is a dictionary and how to create one ?: Hello and welcome to the section on dictionaries. In this section, you will be learning what is a dictionary. The need to go for a dictionary? How to create an updated extra green bite on on some off the operations that can be performed on dictionary. So what is a dictionary? A dictionary is a collection off key value pairs. A dictionary is similar to that of list in less to access the values off list you used the indeed your index off that list or off the value what you wanted. But in case of a dictionary, you will be using the key off the value as the index. For example, you want to store the contact numbers off your friends, so what you will do is create a dictionary. Say you have two friends by name. Ben and Matthew Bent with the contact number 1234 and Matthew with the contact number 5678 So your dictionary would contain a key called Ben. Associate it with the value 1234 and another key called Matthew, with the value 5678 So when you use your dictionary, but the key has been the value. 1234 will be returned on when you use your dictionary with the key as Matthew the Value. 567 it will be returned, so you need to go for a dictionary when you want your value to be associate ID toe a particular key now that you have understood board. Additionally, yes, let's go ahead and implement Dictionary in by Tom. Let's get started by opening Pythons Idol Environment. The syntax to define a dictionary is to have a dictionary, name an assignment operator and then the key value pairs in curly braces, Silverton curly braces. I could have Kiev on value one separated by a comma and key to colon value to now. What this does is key. One has the value of one, and the value to would be the value off my key to Now let's take a look at an example. Say I wanted to create a dictionary to map the praise off a camera to its brand. Let me go ahead and create that so it will be a dictionary to map the praise off a camera, do its brand. I'll call my dictionary s praise off cameras on assignment operator, and I can have the key value pairs within this dictionary. Sochi would be the name off the brand, and value would be the praise associated to that brand. So let me start by creating one for Bryant. Sony say Sony has a camera, which is being sold at $500. Now Sony is a string because of fit. It is enclosed in double codes and 500 is a number because of which he will not be enclosing it within coats. Another brand, which I will be having is Nikon say it s praised at $600 finally I have a brand cannon, which is praised at $700. Now, if I take a look at my dictionary, it will have the key value pairs. Now, in order to retrieve values from a dictionary, we use the concept which we earlier saw, which is indexing. But indexing and dictionary works a little different than it did for tipple, python and strings. So in dictionaries, your index will not be an anti jer value, but instead it will be the keys off your dictionary. In this case, it is Sony, Nikon and Canon so if you wanted the praise off your Sony camera, you call your dictionary, which is place of cameras on as an index. You would pass the key off your brand, which is Sony, and it returns the Value 500 now What if you wanted to update the value off a key, say Nikon has changed the praise off their camera from 600 to 800. How will you handle that situation? So you change your value by entering your dictionary name and mentioning the key to which the value needs to be changed. In this case, it is Nikon, and you assign it, but the new value, which is 800 now. If you try to print the praise off your Nikon camera, let's see what the output will be. The output is 800 which is the new value that you had assigned. That's the end of this lecture. You learned how to create a dictionary, how to retrieve values from addiction risky on how to update the value corresponding to a dictionary, ski the next lecturers about the different operations that can be performed on a dictionary . And I'll see you there. Thank you 17. 9.2 Dictionary Operations: hello and welcome to this lecture. In the previous lecture, you learned water dictionaries. And in this lecture you will be learning some off the operations that can be performed on a dictionary. I have bite on Idol environment open, and in it a have the example from a previous lecture which is a dictionary to map the praise of a camera to its prank. The first operation, which we will be looking at is the dictionary dot keys operation. So what this does is it prints all the keys available in a dictionary. So if we take the example off, praise off cameras and I call keys operation on it, it lists out the keys Sony, Nikon and Canon similar to kiss. We have another operation called values. And as you must have guessed, what it does is it prints out the values available in my dictionary. So if I print the praise off cameras dictionary with the values operation, it returns 506 107 100. The next operation, which we will be looking at, is the dictionary dot copy operation. So what this does is it copies the values the key value pairs from one dictionary to another dictionary. So let's see how that works. Let me create a second dictionary and let me call it Got B off praise off cameras And this will be a copy of my first dictionary praise of cameras. So I called the dot copy function on my first dictionary. On the contents are being copied into my second dictionary to make sure it worked. As expected, Let me print my second dictionary, which is Skopje off praise of cameras. Now, as you can see, the contents are a copy off the first dictionary price of cameras. The next operation is to delete a key value pair say I wanted to delete the key value pair Sony and 500. How do I do that? I do that by entering the key vote D E l space the name off my dictionary, which is praised off cameras. And then I enter the key, which is to be deleted within square brackets, which is Sony. Now, if I try printing my dictionary, it should give me the output without the key value per Sony and it does. The final operation, which we will be looking at, is to clear the contents off a dictionary. Let's see how to do that. So a dis dictionary dot clear and to go by our example off praise off cameras. It will be abrasive cameras dot clear, and if I print it, it should return to me an empty dictionary, which is just a pair off curly braces. So that's the end of this lecture and the section on dictionaries. Let's take a quick review off what you have learned in the section. We started the section by discussing about what a dictionary is, which is a set off key value pairs that are referenced by a single name. And then we saw how to create a dictionary. You have a variable name and an assignment operator, and the key value pales within a pair off curly braces. So you enter the first key and then the value associated to that key after a colon. And then you separate key value pairs using comma, so you first have one key value pair. You enter the comma and then you have the next key value pair and so on. Now we have an example dictionary, which is color of fruits. What this would do is it stores the name off the fruit as the key and the value as the color off that fruit. So in this example, we have color of fruits with apple, yellow, orange as name off the fruits on red, yellow and orange as colors off the fruits, respectively. And then we saw Ho to retrieve values from a dictionary to retrieve values the similar to that of a list or a triple. But instead of mentioning the in teacher as index, what he will do is mention the key associated to that value as the index. So you call the dictionary color of fluids and passed the index as the name off the flute to get its color. So if I need to retrieve the color of the fruit mango, I would say color of flutes and index it with the key mango, and that should return the color yellow. And then we saw how to update a value associated toe, a dictionary key to a greater value. All you have to do is call your dictionary, but the key that you want on, then assign it with a new value. So if I need to change the color off apple, I would say color of fruits pastor, in example, and assign a new value in this example have assigned the value green. So I dictionary now has the value modified as apple with the color green. And then we saw some off the dictionary operations. The first operation, which we check, was the keys operation, which lists all the keys off your dictionary and similar to keys. You also have the values operation, which lists all the values off your dictionary. And then what we saw was to delete a key value pair using the del que So you say del with the name off your dictionary on the key for the key value pair, but you want to delete. So if I want to delete the key value, pair apple, call my dictionary and passed the index as apple and that would believe the key value. Pair apple and green and return the output off my dictionary as orange and mango with apple removed from the dictionary. Next, what we saw was to copy the contents of one dictionary to another dictionary. To do that, create a new dictionary. Let's call it a copy of color off fruits and assign it with the value off your dictionary dot the copy function, so that will copy the contents off your dictionary into another dictionary. And finally, what we saw was the clear operation, which is used to clear the contents off your dictionary. So if you call it with color fruits not empty, that would return a pair of curly braces, which is an empty dictionary. So that's the end of review. On the section on dictionary, go through all the pdf notes attached and exercise problems. Use the discussion. Vote in case you need any help from me. The next lecture, we will be discussing about conditional statements by this dictionaries. We have come to an end off the data types and fight on from conditional statements. We will be starting to learn how we can manipulate all this data and fight on. I'll see you there. Thank you. 18. 10.1 What are conditional statements ?: hello and welcome to the section on conditional statements. Now that you have a strong understanding on the different data types and bite on, we will now learn how to manual plate. All this data in this section we will be learning work are conditional statements. The different types of conditional statements available in bite on help is logical operators, along with the condition statements. And at the end of the section, we will be writing a complete problem and bite on that implements conditional statements. Until now, you have bean using the vitamins I little environment to practice the concepts. But now you will be using a text editor to write a complete fight on program. So to start with water conditional statements now, conditional statements are statements whose execution depends on the evaluation off a certain condition. Let's take a look at an example. Take the alarm clock off your phone. You set an alarm at 5 a.m. So what happens? There is a constant check that is being made to check if the time in your phone as 5 a.m. So once the time on your phone is 5 a.m. The alarm rigs now when we use logical operators along with conditional statements. Now, if you can remember, logical statements are on or not. So to take the example of the same alarm clock, if you set an alarm for Sunday seven AM what happens? A constant check is being made to check if the day is Sunday. So once the day is Sunday, another chick is constantly being made to see if the time is 7 a.m. So if the day is sending on the time of 7 a.m. then the alarm race. Now that you have understood water, conditional statements, let's go ahead and implement conditional statements and bite on in the next lecture. I'll see you there. Thank you. 19. 10.2 Different types of conditional statements: Hello and welcome to this lecture. In the previous lecture, you learned water conditional statements and went to use them. In this lecture, you will be learning how to implement conditional statements on the different types. Let's get started by opening Pythons, Idol, environment The first conditional statement which we will be talking about this the if condition Now let me define variable using which we will be learning how an if condition is implemented. So I have my reliable total marks and let me a sign it with the value 95. So what an if condition does is it takes in a condition and validates it to either true or false. If the result off if condition is being validated to true ah, block off good follows which is then executed. No, If my if condition validates the falls, that block of code is not executed. Let's see how that books Now I will be writing in if statement to check if my total marks exceeds or is equal to 90. I do that with the help of relational operator. So I checked. If my total months is greater than or equal to 90 and end my statement with the colon. So what the colon denotes is that there is a block of court following the if statement, which is to be executed if my if condition evaluates to true. So under this I can have my prints statement with Saiz. Congratulations. You have secured and agree. Now what you need to note here is the indentation that is being provided now bite on mandates the indentation, which means the block off. Good under your if condition should have an indentation and it is mandatory. Now, I can have multiple lines under this if condition, but all of them should have the same indentation. Now, if I execute the statement, let's see what the result will be. I have my residence. Congratulations. You have secured and agree. Now let's see what happened initially, the value stored in my valuable total marks is 95 now the if condition checks with the value 95 it checks if 95 is greater than or equal to 90. Which is true on successful execution. It prints the statement Congratulations. You have secured and agree. Now let's see what happens if my total marks was 80. Let me just copy paste the same coat. Now, as you can see, there is no output. So what happened? The total marks 80 is not greater than are equal to 90 because off which this print statement was not executed. The next statement rich we will be looking at is that if else condition know what NFL's condition does is the else is more like a backup plan. Say what if my if condition failed like in this case in that case, you you can have a block off court under your else condition which will then be executed. Let's see how that works. Now I have the value 80 in my total marks. So let me have the same if condition to check if the total marks is greater than or equal to 90. Andi, then what you need to make sure is to start your else condition from the beginning. Off the line, the if conditions started from the beginning off the line. Don't let these lines confuse you. This is the beginning off the line where if conditions started on your else should be in the same indentation, which is the beginning off the line. Now, in my else, I can have a block off code which sees you have cleared the examination. Now let's see on execution off this Ifill's condition what my result would be. As you can see, the total marks is 80 which is not greater than or equal to 90. Because off which this execution fail on. Then my else condition got triggered on. I have the output As you have cleared the examination. The next statement which we will be looking at is the if l if statement or rather the condition. So what? And if LF does, is you can have an if condition with NL's condition. So if your first if condition failed, you can have another if condition which will check for another condition. So let's see how that works. So let me reassign total marks with the value 60. Now, if I see, let me just copy based the same if condition. Now this condition will feel because total marks is equal to 60. So next water will do is to have an l f condition. So what it does is the else statement gets triggered and I'm having enough condition. The combination is called. LF so here I check if my total marks is greater than or equal to 40. In this case, I print a statement and say Congratulations. You have cleared the examination. No, you can have multiple LF conditions so I could have another. LF condition following this which will get executed if this LF condition fails and at the end of all the LF condition you can have an else condition which triggers if all the other fn LF condition fails in this case let me print You have failed the examination So now on execution off this if LF condition Let's see what the output will be We have the open as congratulations You have cleared the examination So what happened is I have the value 60 in my total marks on it first checks if 60 is greater than or equal to 90 which is false because of which this if condition evaluates to false now the next LF gets triggered and I check if my total marks 60 is greater than or equal to 40 which is true now since this evaluated to true the block off statement on that this got executed which is to print the statement Congratulations. You have cleared the examination. Now, in case my total marks was less than 40 it would have printed you have failed the examination. The final condition which we will be talking about is the nested if condition. So what is invested of condition in f condition. But then another. If condition is called a nested of condition, let's see what That this Let me reassign my total marks to 100. No, let me have the same if condition, which is to check if my total marks is greater than or equal to 90 now. Within this if condition, I'll also check if my total marks is equal to 100. If it this then I will print a statement. You have also secured full marks. No, let's see what the or put off this execution will be. So my total marks is greater than 90 because of Fritsche. A printed congratulations you have secure and agree. And also this if condition within the previous of condition is also true, which is my total max 100 is equal 200 I have the output. You have also secured full marks. That's the end off this lecture. You learned water and air conditioners. How if else condition works how indentation works in python you learnt about if LF conditions And finally you learned how an if condition works within another of compassion The next lecture we will be discussing how to have an if condition, evaluate multiple conditions But the help off logical operators. And I'll see you there. Thank you. 20. 10.3 Using logical operators in conditional statements: Hello and welcome to this lecture. In the previous lecture, you learned how to implement different types of conditional statements on in this lecture, you will be learning how to evaluate multiple conditions within a single if condition by making use off the end and are logical operators. Let's get started with the and operation to take a quick review off the and Operation and and Operation needs both of the conditions to be true in order for it to return the licit. That's true. So, for example, I can have a condition to less than five and 10 greater than seven. So, too, was less than five and 10 is greater than seven, and I get the value true now, in order to understand how and works along with if, let's take an example from the previous example, let's take total marks and assign it for the value 95 let me have another variable and call it percentage off attendance and a sign it with the value 93. Now what I want to do here is to evaluate that my total marks is greater than 90 and also evaluate that the percentage of pertinence is greater than 90. I do that by using an and operation with an n f tension. So I right if my total marks is greater than or equal to 90 and my percentage off attendance is greater than or equal to 90 on, we provide an indentation and then print this following statement which will be executed if both my conditions are true riches. You are a very disciplined student. Let's see what the execution off this if condition would give us there. You are a very disciplined student. So what happened? There is the total marks was greater than 90 and the percentage of attendance was greater than 90 because of which both the conditions got evaluated to true on my if condition returned true. No. What if one of the conditions were false? Say, for example, let me reassign my percentage of attendants. So say 60. What? Then let me copy paste the same condition and executed to see what happens. As you can see, there is no output. That's because the second condition off my and operation failed on the if conditional turned falls and it failed to execute any further the next operation, which we will be looking at is the our operation now too quickly review what in our operation does And our operation needs just one off the two conditions to be true in order for it to return the value as true. For example, let me have a false condition too is greater than five and ordered. But then of the true condition say 10 is greater than seven Now this is a false condition and this is a true condition now, since one among them are true, my output will be true. Now let's see how all works along with an if condition. Now let me take an example off a fruit fruit, equal toe apple Know what I'm trying to do here is in my if condition I will be checking if my fruit is an apple or a mango. Now, in order to do that, I have my if condition where I check if my fruit is equal to mango, the double equal to Stein's. For comparison. Another way. How you can perform comparison and fight on on this is the more platonic way is to use that is keyboard. So I check if my fruit is mango or my fruit is apple and then I have my prints statement and I print I love that fruit. Now let's see what the output off our execution will be. The output is I love that fruit. So what happened? The name of my fruit was apple on my if condition first check if the fruit is mango. Now this is false as my fruit is apple. So in the all condition I have a check to see if my fruit is apple, which is true. And since one off the two conditions are true. I enter my if condition on dit prints the statement. I love that fruit Now What if my fruit was something else? Say my fruit was strawberry. So what would my output be then? Let's print the same condition and see what the output will be. So as you can see, I do not have an output. And that's because both the conditions failed on the if condition did not evaluate a true because of Fitch. We did not have the prince statement executed. So that's the end off this lecture on the section on conditional Let's have a quick review off what we have learned in the section. We started the section by discussing what are conditional statements there block off statements whose execution depends on a certain condition. And then we looked into the different types of conditional statements available and python . The first type of conditional statement is the if statement. So what does in if statement do it checks for a condition. And if the condition is true, then the statement under if gets executed in this example, we assign 100 to available distance and then we check if the distance is equal to 100 now, double you could do is a comparison operator. It checks if the operator at the left hand side is equal to the operation at the right and site. So since distance is equal to 100 we get our output as distances 100. The next type. What we looked into was, if else statement so what does this too? In case you're if condition fails, the block off statements in your else section gets executed. So in this example, we are ST 200 to the variable distance and then we check if the distance is less than or equal to 100 which is false now that this If condition has returned falls, the block of statement in the else section gets executed, which is to print that the distances greater than 100 the next tape. What? We check waas if l f else. So what is this if l a fells l f stands for else if which means if you're If condition fails, you're making another. If condition check as a part of your statement, let's take a look at this example. So we assign a value 200 to the valuable distance, and first we check if it is less than or equal to 100 which is false. And then we check if that if conditioners falls, make another, if condition check else. If check the distance is less than or equal to 200 which is true and on open off, the program will be distances less than are equal to 200. Now engage. Even if this statement had returned falls, we have a final else statement in which our execution would have bean distance is greater than 200. But in this case, since the distance is equal to 200 our output would be distances less than are equal to 200 . And finally what we check was the nested if statement and what is in instead of statement, it is an if statement within another of statement. So, for example, we assign a value 50 to the variable distance and then we check if the distance is less than 100. Which is true now that the evolution off if has turned true, it enters the block of statement. And if there another condition is being checked, another if condition is being checked. Very your checking if the distance is 50 so you're making an if condition check within another if condition check which is called a nested if statement So that's the end of this review. In the next lecture, we will be implementing a program in Python which will make use off conditional statements . I'll see you there. Thank you. 21. 10.4 Program - Check if a number is multiple of 3 and 7: in the section, you learned how to use conditional statements. Now let's make sure that you have your understanding right by writing a Python program. Now, so far in the schools, we have been using Python's idol environment to practice the concepts. Now that we have practiced the contents of conditions, we will be writing a complete program and Python in a text editor. Now the text editor, which I will be using, is the atom text editor, which we had installed in the beginning off the scores. Now let me open it up by hitting a command space on my Mac and entering Adam. Now, if you're on linings of windows, you can do that by hitting Windows key on your keyboard and entering at him. Now, in case you do not have at him, that's completely all right. Just make sure that you have a normal text editor and rest. You can enter your python code. That could be your note pad or any basic text editor in your Mac Align X. So let's get started. Let me first save this file. Your file name can be any name off your choice. I will be naming it as multiple, since the program which we're dealing with us, got something to do. What finding? If a number is a multiple off another number or not, just make sure that you're ending it with the extension dot TV I that denotes year file as a fight on file. So now let's get to a problem statement. Our problem statement is to check if a number is a multiple off three. And now, if that number is a multiple of three, we also need to check if that number is a multiple of seven and print appropriate statements. So let me just write down the problems statement. It is to check if a number it's a multiple off three and if it this also check if it is a multiple of seven. So how do we check if a number is a multiple of three Now you must remember the Modelo function, or rather, the modular operator, which we had learned. Now we will be using the modular operator in this program. And how do we find if a number is a multiple? You divide that number by three, and if the remainder off your division of zero, it means that number is a multiple of three to take an example. If I divide the number six by three and if the remainder off my division, which is denoted by the model assemble If that has the value zero. That means it is a multiple of three. Say, for example, if I try to check the foreign number, that is not a multiple of three. For example, on number 10. Now, if I divide 10 by three, the remainder list to which is a non zero number. So what you need to understand is if the result off your division has the remainder. Zero. It is a multiple of three, and if your result is a non zero, then it is not a multiple of three. Now let's first create a valuable to hold our number. So let me create a variable called number and assign it for the value say six. Now what I need to check is if the remainder off division when divided by 30 or not, I do that with an if statement. So if my number more dillo three. So I'm dividing this number by three and checking if my remainder is zero now that's the platonic way off comparison to use the escape. But on then I print the statement telling number is a multiple off three. So what does our problem statements a next. Now, if the number is a multiple of three, also check if the number is a multiple off seven. So I check if my number more 70 This is to check if my number is a multiple of seven or not . In that case, I will be printing a statement that says number is also a multiple off. Seven. No wort. If the number was not a multiple off seven in that case, I would have an else statement, which would print number is a multiple of three, but not a multiple off seven. Now let's see the open off this program by running despite on program. So first we will have to save the file, but the file and click on Save Now. If you're on Mac or Line X, you can open your terminal to execute this program. And if you're on Windows, you could either use command prompt or you could use powershell, whichever you have been using as a command line interpreter. So I do that by hitting a command space and entering terminal now to execute my python problem. The syntax is to give Python three space the part to your fight. Now this file multiple dot be by lies in my best up. So I go to my desktop slash and then I enter my filing, which is multiple dot Levite No, on execution off this begin. See, that number is a multiple off three and since it is not a multiple of seven, we have the output number is a multiple of three, but not a multiple of seven. Now let's try to do something different. So far in the scores, we have bean entering hard coded values. Now what do I mean by hard coded values? These numbers which you have entered, say, for example, the number equal to six which have entered the value is a part of your program and cannot be changed during execution. No, What we will be doing is to give the user off your program a prompt to enter the number and take the number from the user. So let me do that by first giving a prompt to the user with the Prince statement. So I'm telling the user, Enter a number and then what I do is to read the input from the user. I used the function input, So input function lets a steak input from the user. So whatever input is being taken from the user is being assigned to the valuable number. Now let's see how this works. By executing this program, let me save it and open my terminal. Now if I execute this program, I can just press the up arrow key to execute my last executed command on terminal. And then, if a president Turkey, that gives me a prompt to enter a number. Now say, this time I enter the number 21 let's see what happens. So that raises an exception type error. So what happened was your input function by default takes your value as a string. Now you cannot perform an arithmetic operation on a string. What you need is an impeach number. So if you remember typecasting to convert this into an anti jer, you need to enter end and then call the input function within parenthesis. Now let's see water output will be by saving it and executing it one more time. So this time I enter the number 21 on my output is numberless a multiple of three. Number is also a multiple off seven. So now that you have a form understanding on how conditional statements work, let's move on to our next section, which is about loping statements. Thank you. 22. 11.1 What are looping statements and implementation of For loop in Python: Hello and welcome to the section on hoping statements. In this section, you will be learning what a loping statements, the different types off looping statements and bite on on how the break continue on else statements work along with looping statements. At the end of the section, you will be writing a program and fight on that implements loping. So what are hoping? Statements? Loping statements are statements that get executed repeatedly as long as a certain condition holds true. For example, take the ceiling fan in your room, or any electronic device, for that matter, as long as the switch is being turned on. Rotate the blades of the fan on. Once this, which is being turned off, stopped the bleeds from rotating. So that's exactly how looping works the different types of looping statements and fight on R four and while loops and we also have a concept called Nestor. In this lecture, we will be discussing water for loafers. Let's see what that IHS let's get started by opening bite owns Idol environment. So to start with what is a for loop follow up is a loping statement which is used to it rate over the sequence. Now the next question. What is a sequence sequence? Can be anything like your string, your list or a triple etcetera. Let's take a look. For the help of an example, let me create a list called fruits and assign it with the values apple, mango, orange and, finally, strawberry. So if I print my list, this is what it would look like. No. What if I wanted to print the individual elements off this list? I wanted to print apple first and mango that our engine dense trouble. One obvious answer is to print them one by one, so my answer would be fruits and index off the value, which I need for apple it. Zero. So that would return apple. And for mango, it would be fruits, but an index. I mentioned the value vine and that would on the value mango and so on. Now this is a tedious process. What if your list had, say, around 1000 elements? You obviously will not be able to write 1000 print statements. So one clear cut solution for that is to use a for loop. Now let's see how far look works by looking at the syntax off a for loop. The syntax of a for loop is to start the for loop with the four key vote and then to have a variable name which will be used. It rate over your sequence and then you have the in keyword and finally you have the sequence. Now let's see how this works on our floats list. So for my variable in which I'm using this fruit in the name of my sequence here is fruits . So what happens here is in every iteration off my loop. Fruit takes the value off the list, starting from apple than to mango and an orange and finally strawberry. Now let's go ahead and print the contents off the fruits list. Now I have written the for loop statement and I'm ending it with the colon, which means there is a block off statements which follows this for lope statement. And then we start with an indentation which could either be a tab or a space like how we had done it in conditional. And then what I do is to print the fruit. Now let's see what the are put well being. So as you can see, I have all the elements off my fruits list starting from apple, then mango than orange and finally strawberry. Now the next function which we will be talking about is the range function which we haven't bite on. See, for example, you wanted to generate numbers from 1 to 10. How do you do that? You can do that with help off range function on the for loop. Let's see how that works. So I can have four and the number in range 1 to 10. So what this would do is in every alteration. My number will take values from 1 to 3 and so on. So if I print my number, let's see what the output will be. So as you can see, the output is 123 and all the way up to nine. So what you need to remember is the ending range, which you mentioned, needs to be one more than what you need. Now, since in this example, I have used in the range one comma 10 it prints up to nine. Now, if I wanted up to 10 my value mentioned should be fun. Come 11. So that's the end of this lecture you learned water for loops. You learned how to write a for loop and how to it rate over the sequence. You learned how to generate a range of numbers. I'll see you in the next lecture where we will be discussing about Violet. Thank you. 23. 11.2 While loop implementation in Python: Hello and welcome to this lecture. In the previous lecture, you learned how to implement the for loop. And in this lecture you will be learning how to implement a violent to start with what is a violet. Violet is a looping statement that executes a block off code as long as a certain condition . As evaluated to truth. Let's take a look at how I look. Works for the help off An example. Let me define a valuable temperature that is used to store the room temperatures. Say I start off by declaring it for the value 77 F. So what I want my program to do is to print the temperature as long as it is being maintained in the room temperature. The range for room temperature is 68 to 77 F. So how do we do that? I have my via loop on in my via loop. I will be checking if my temperature lies in the range 68 to 77. So I compare. Temperature is greater than or equal to 68. And if my temperature is less than are equal to 77 if this is true, I enter my via loop and I print the temperature so my print statement would be room temperature is maintained at No if you remember what these curly braces are there placeholders for your valuable names. So this place holder will be replaced by the temperature. So in this case, it would print room temperature. It's maintained at 77 F and they for my my string and I enter the variable in temperature. So what I will do next is to reduce my temperature by 1 F, so my temperature will be temperature minus one. Now, let's see what the execution off this via loop will look like. They're so it started with room temperature being maintained at 77 F on that went all the way from 76 75 to 68. So after 68 what happened is your room temperature was reduced to 67. Now, since 67 is no longer in the range, 68 to 77 are violent breaks, and we come out off the loop. Next. What? We will be talking about this and in finite via loop, we can have a via look that runs forever by mentioning the condition in the violet as true . No, I can have a print statement that say's This loop runs forever now on execution. Off the statement this loops prints on and on. Now I have hitter control see on my keyboard to stop it from further execution. I just wanted you to know that something like an infinite via loop exists, though it does not make much of a sense in this example. A real time example could be the led light that gets turned on when you plug in your mobile phone for charging that led light remains that way. And that's done by using on infinite Loop. So that's the end of this lecture. You learned what is a via lope you learned how to implement of I looked. And finally you learned what and in finite via Lupus. In the next lecture, we will be discussing about what nested loops are and I'll see you there. Thank you 24. 11.3 Nested loops implementation in Python: Hello and welcome to this lecture. In the previous lecture, you learned how to implement a while loop, and in this lecture you will be learning board and nested Lupus, so water nested loops. The definition off a nested loop is similar to that often Nestor Death statement and it say's a loop. Within another loop is called a nested loop. The point you need to remember is for each iteration off the outer loop. The inner loop will be executed from beginning till the end. Let's understand that with the help of an example on my bite on Idol environment, I have a format off a matrix, which I want my program to print now, in case you're not sure what The Matrix is, A Matrix is a mathematical representation off numbers in terms, off rows and columns. The horizontal lines are called rose, and the vertical lines are called columns. Let's see how to implement a matrix with help off nested loops. Let me start by declaring a variable called number, which I will be using to print in my Matrix, and the initial value for my number will be one. No, I will have two loops. Want to run the outer loop, which will be for the rose and another one for the inner loop, which will be looked through the columns. So for row in range one comma four. Now, if you remember, your ending value needs to be the value, which you need less one. Now, since it is three rows that I need here, my value should be four. Now, in my inner loop, I have my column loop and I started for column and range once again. Since it is three column spur grow, it is one comma food. Now let me go ahead and print the number. No, usually what happens with the Prince statement is it prints the statement and goes on to the new line. Now, in this case, you do not want that to go to the new line. As you can see after one, a space is being given, and then you enter the number two. So at the end off every Prince statement, I need a space. You can do that by giving the para middle end on adding a space to give a space. You enter a single or a double coat and you give space in between, so that at the space at the end of every print statement now what happens is the number is being printed thrice. But that's not what you want. You want the number to increment as well. So in my next statement, I assign number equal to number plus one. So what this would do? Is it increments the number by one? So the first time it prints one the next time the number is being incremental. +22 And it prints, too. And next time the number is being implemented to three and friends three and my column loo breaks, survives my column. Loo breaks. What I want. My program to do is to print a new line so that the next row starts from the next line. And how do I do that? I go back to the indentation off my role loop, which is just before I started the indentation from my column Look, and there I print a new line by having an empty print function. Now let's see what happens on the execution off this nested loop. So as you can see the first time the row had the value one on for that iteration column was executed thrice. So you have three columns with the values 1213 And then you had a new line statement, which caused the output to go to the next line and for the next iteration off room. Once again, your column loop was called thrice and you have the values 45 and six. And then you print the new line. And finally, for the third iteration off your rollup, your column loop was once again called Tries on We have the output 78 and nine. So that's the end of this lecture. You learnt water nested loops and how to implement a matrix using a nested loop. The next lecture, we will be discussing how the break continue and else statements affect the behaviour Off loops. I'll see you there. Thank you. 25. 11.4 Break, Continue and Else: Hello and welcome to this lecture. So far in the section you have learned how loping works in this lecture. You will be learning how break continue and else statements can be used to manipulate your loping statements. Let's start by looking at water break statement. This So what a break statement does is based on a certain condition. It stops your loop from further execution to understand how that works. Let's take an example say I want a print numbers from 1 to 10 so far number in range, one comma 11. I given indentation and then I would print it. Now what I want to do is to stop this loop from executing on reaching the number five. So I have a condition with checks. If my number is equal to five, then you break the loop as print the number. Let's see how this works. So as you can see the output this 1234 So what happened there is on reaching the number five. This if condition evaluated true on the break statement was executed, which cost this loop from executing any further. Let's see what a continue statement does. A continue statement is used to skip a particular iteration. Let's see what that does. Let's take the same example off printing numbers from 1 to 10. So for number and range 1 to 11 now, in this case, what I would want my look to do is to print all the numbers from 1 to 10 except the number five. So on encountering number five, I need my alteration to be skipped. Let's see if that works by using. Continue. So if my number equal to five, then continue Els print the number. So as you can see, the output is 1234 on reaching the number five. The if was evaluated to true and the continue was executed, which cost that particular inspiration to stop and continued with the next operation, which is six and 789 and 10 were printed going forward. Next What? We will be looking at this the else condition? No, we have seen how else works along with an if condition. Now let's see how else works along with the loop. So how else works? Is it checks for the break statement in your loop Now? If the brake statement was not executed, then the else blood gets executed. Let's see what that is. So for number in range 1 to 11 This time let me check if number is equal to 15 which will never happen since I'm only printing numbers from the range 1 to 10. In this case, if the number is 15 or you break the loop and then in the l section I enter print number. So do not get confused. This is the else corresponding to the if statement. Now we will be writing the else corresponding to the four loop statement. And to do that I go back to the beginning off my line and in the l section I print a statement that say's all the numbers were printed without breaking the loop. Now let's see what happens there. As you can see, all the numbers from 1 to 10 were printed. And since the break statement was not executed, the else block was triggered on it printed the Prince statement in the else block. No, what if my break statement was executed? Let's see what would happen then, for number and range one common 11. This time I will be checking for a valid case and I'm checking once again with the number five. If it's the number five break Els, I go ahead and print the number. Now in the else block, I give the same print statement. All the numbers were printed without breaking the loop. Let's see what happens on execution off this loop. So what happened is it started execution with 123 and four. And since the break statement was triggered when the number five was encountered, it broke the loop. And since the loop was broken, the else part of the loop was not triggered. That's the end of this lecture and the section on loops. Let's take a quick review off what you have learned in the section. We started the section by looking at by a sloping used riches to repeatedly run a block off statements over and over again. And then we saw the different types off looping statements. The first we saw is the for loop, which is used to rate over the sequence, starting from the first element to the last element. Now, in this example, we have a list called Numbers, which has the numbers 12345 So we can use a for loop to run across this list, starting from the number one till the number five printing off the numbers in the list. Next, what we saw was the violent. Now ah, via lope is used to repeatedly execute the block of statement as long as the condition in the violet holds true. In this example, in our Via Lupo, we have a valuable called length which is being checked. So what is happening is it checks if the length is less than or equal to three? Initially, the value off the variable length is one and within affordably incriminated and printed survives the value off linked owns for it breaks the flu, the next kind of flu. What we saw is the nested loop, which is a look within another loop. So in this example, we have used two for loops in 14 look within another four group the number of times this local execute is M. Cross and where M is the number of iterations off your outer for loop and N is the number of it relations off your inner for group. So for every operation off your outer for loop, your inner loop would execute three times. So it is a total of three into three number of times. So in this case, it will print a total off nine times the statement. Hello, world next. What we saw was the break statement. So what is a great statement? A break statement is used to break a loop from for the execution when a condition is met. So in this example, we check if the length is equal to three and if the length is equal to three, we break the violence. Next, what we saw as the continuous statement which will skip a particular inspiration after loop . So now a brave statement completes the loop from for that execution when a condition is met . But a continue statement skips just one particular inspiration off the loop. Now, in this example, what happens is initially the value off. The variable length is one. And in our via Lupo, we run the slope as long as the value off length is less than or equal to four. Know what condition were checking within the violet is if my length is equal to two, then increase the link and then continue. So what happens is when you're length is equal to two without printing the length you implemented to the next number, so are open. For this would be 13 and four. When you encounter the length with the value too, that particular inspiration gets skipped. Next, What we saw was the statement. So how does an else statement work along with the loop? So an else statement gets executed when the break statement off the loop does not get executed. So what does that mean now? In this example, we have length equal before and Britain are loop within our violent. We're checking if lengthy with three. Then break this via loop, which is never going to happen now. Since the break statement is not being executed at the end of this violet, the else statement will be executed on it will print the output break was not encountered. So that's the end of this review on loping statements. In the next lecture, we will be writing a program and python that implements loping. Now, in case you have any doubts on the concept off loping so far, use the discussion board and I'll help you from there. I'll see you in the next lecture. Thank you 26. 11.5 Program - Check if a book exists in your collection of books: Hello and welcome to this lecture. In this section you learned what a loping statements and to make sure that you have your understanding on looping right, let's go ahead and write a program and bite on that is based on loping. So let's first start by opening a text editor. The one which I use is Atom. So what program are we going to, right? Let's take a real time example. Say you have a collection off books and a friend of yours wants you to check if you have a particular book with you or not. So what you would do is go through your collection of books and then let your friend know whether or not you have that book in your collection. Let's first save this file. I'll be naming it as find book dot Levite. Just make sure that you're giving the extension dot Be by to identify your file as a fight on file. So once again, to get a problem statement right, it is to check if a book is existing in your collection. So what is the first thing that you want to do? You want to create a collection off your books. And how do we do that by making use off a list. So let me create my list and name it collection off books and then let me go ahead and have three books in it. The Alchemist. How to Win Friends and Influence People and finally, the seven habits of highly effective people. Now what do you want to do is to give a prompt to your friend to let him enter the name off the book, which he wants you to check. So to do that, I have a print statement that say's enter the name off the book, and then I have a variable name in which I will be holding the name entered by your friend . So let me call it a book to be checked. And then we called the input function. Now, if you remember what an input function does, it takes input from the user and stores it and this variable in string. Former. So now that you have the book which you want to check, let's run a for loop across your list to find out if you have this particular book in your list, and how do we do that four book in your list, which is collection off books. So what the statement does once again, is it checks. If this book which will have the value in the first iteration as the alchemist in the second operation it will have the name off your second book on in 1/3 iteration, it'll have the name off your third book. So you will be checking in each iteration. If this book is equal to the book which your friend is talking about And to do that we make use often if condition. So I check if my book in the list which I have is equal to the book to be checked. In that case, right. A print statement that say's yes, you have the book in your collection. So let me call. Yes, I do have that book. No, what if you do not have that book? The normal tendency as a big enough for us would be to go to the else statement right here . Now what happens here is if you give the else statement, say, for example, your friend wants you to check if you have this book, how to win friends and influence people so in l statement. If you print, I do not have that book. Then what would happen is in the first iteration, the book will have the value of the alchemist. And you will check if alchemist is equal to how to win friends and influence people. Now. Since that is not equal, this else close gets triggered. And then you print the statement. I do not have the book. Then in reality, you actually had that book. So let's get rid off this l statement. And if you remember, we can make use off a break statement once we have found the book. So in this case, A for example, my friend wanted me to find the book alchemist. So as soon as I find the alchemist, I no longer need to go further in my list. I can break my loop right there and then we have a condition toe print when you haven't found the book. So if you remember the else statement corresponding to a lope, the else is executed. When your break statement is not executed. Which means at the end of the list. If the book was not found, then this if condition never gets triggered and your break statements never get executed. So in the else corresponding to your four look, you can have a print statement that say's No, I do not have that book. Now let's save this file and executed to see what our output will be. So to execute it, I opened terminal on my Mac. If you're on Windows, you could use command. Prompt a power shell. If your line X you could use that same terminal. So to execute this program, I enter fight on three and then I navigate to the location off my file, which is placed on desktop, and the name off my file is fine. Book, find book dot be Fight. So enter the name off the book. See the name which my friend wants me. The check is the alchemist, so I get the output that says, Yes, I do have that book And that's because this if condition got triggered, no. What if you do not have that book in your collection? Let's see how to handle that guest. Let's open our terminal once again. On this time, we will be entering the name off a book which is not present in our list. So on executing it to enter the name off a book, let me see Tuesday's with mooring. No, what happened is the else statement off your for Luke got triggered on since the break statement was not executed, you have printed the statement. No, I do not have that book. So that's the end of this lecture on Now that you have a really strong understanding on loping statements, let's go to our next section, which is on functions on before you get there, make sure that you solve all the exercise problems attached in. Pdf on also go through all the notes. Thank you, and I'll see you in the next section. 27. 12.1 What are functions and how to define one ?: Hello and welcome to the section on functions In this section you will be learning water functions and why to use them. How to implement a function bite on how to pass para meters and return while this from a function. And finally you will be writing a program and fight on that implements function. So what is a function of function? Is a named unit of code that both arms a specific dusk. For example Take the call button off your phone. What does that do on your dial back? You enter a contact number and you press the call button On present the call button a function call is being triggered, which is to make a phone call. No functions are reusable. Piece of code. What does that mean? Only what your day was Pressed the call button through a dial pad. But now what? You will do this. Go to your contacts. App off your phone. Search any contact on press the call button from your contacts up. Now the result will be the same, which is making a phone call. So the same call button was used in multiple places to perform the same function. Now This is called code reusability, and this is the major advantage of a function I would highly recommend and encourage your to do to use as many functions in your code as possible. That makes your code really easy to read on. You can reuse the good as many times as you want. Now let's go ahead and implement a function and fight on. Let's get started by opening Pythons Idol Environment. The syntax to define the function is to have the D E F keyboard with stands for define, followed by the function name and an open and close parenthesis, which the notes that it is a function and ended with the colon, which denotes that there is a block of code that follows dysfunction, and then you provide an indentation and enter your block of coat. Now let's see how it works. With help off an example, I will be defining a function called Hello Bull, which would print a line. Hello. Well, let's see how that works should define hello world. Do you remember the four rules you went through while creating a variable? The same rules holds good for a function name as well. Now the operation which my function has to perform, is to print the statement Hello world. So that's called as a function definition. Now, once you're function, has Beene defined, it can be called in any part of your program. All that you have to do in order to call your function is to mention your function name, which is hello world with a pair off open and close parenthesis, which the notes that it is a function called now on execution off it. The flow off control is being transferred to the block off court off your function and it gets executed. Now. The importance off a function might not seem very crucial to you in this example. But functions will be a very important topic which you will be using throughout your program. One off the major advantage of a function is functions are reusable piece of code. Now what do I mean by saying reusable? It means a function which is once defined can be called any number of times across your programs, and also the same function can be imported to your other programs as well. That's the end of this lecture. You learned how to implement a function. In the next lecture, we will be looking at an example in which functions will be used to reduce a lot of code in your program. And also we will be looking into examples where you get to pass para meters two functions and get return values from functions. I'll see you there. Thank you. 28. 12.2 Functions with parameters and return values: Hello and welcome to this lecture. In the previous lecture, you learned how to implement a function and in this lecture you will be learning how to remove redundant code off your program with the help of a function. And also we will be learning about Param. It raced functions and functions, but return values Let's get started by opening pythons Idol environment Now The example which I will be using here, is to compute the area off two rectangles know the formula to compute the area off a rectangle. This area equals length into vit. No, let me go ahead and define the variables off my first rectangle the length and width off my first rectangle. So it does length of one. Let me have it as eight centimeter and with one which I will be having asked three centimeter now in order to compute the area. The formula is area one equals length one start Vitaly No, on printing my area one, I get the output as 24. No, let's compute the area off for second rectangle. Let me define two more variables. Length two with the value 10 centimeter and with two with the value for centimeter and my area to would be length to into with two no on printing area to I get the result. 40 witches stand into four. No, you do see the pattern, don't you? For every area opportunity to compute, you need to write the same code over and over again, which is to compute the area. Now we will be overcoming this with help off a function. So what I will be doing now is to create a function which will compute the area off a rectangle. Let me create a function called compute area and it will lacks a two para meters length on with. So this is how you acts of parameters in the function within the pair of parenthesis, you mention the variables which you need to accept and put in the body. I know define area equals length into it and then I print area. No, I have my function Compute area, which has being defined on this particular function, can be used now for any rectangle. Now, let me go ahead and implement this on my first rectangle. So the computer area off my first rectangle now all I have to do is compute area and within parenthesis. I passed my length and my vit. Now what you need to note here is the variable names can be different now. While calling a function, I passed the value length one which has the value eight But while receiving it, the name need not be the same. So I have length one here and lengthier and have vit one here and with here. The only thing that you need to make sure off is that the order off assignment is the same . Now, in case you have changed it with passing wit one first and then length one, then the value will be assigned with it and then the length. So make sure that the order of passing your arguments is right. Now, if I execute this function, I get the value 24 which is eight into three. No, similarly, I can do this operation for the second rectangle as well. Length to aunt with two. Now you do see how function has helped us produce a lot of code in our program. Now the next type of function which we will be looking at its function with return values. Let me go ahead and redefine dysfunction. Compute area. Accepting the perimeter off, lengthened with and I'm computing it as length into it. Now what I will be doing here is instead off printing the area. In this statement, I will be returning it back to my program. So to do that, all I have to do is use the return keyboard and passed the name off the variable which has to be returned. Now let's go ahead and check how that works. Now what you need to make sure while returning a valuable is that you have a variable which accepts the return value. So in this case, I have my variable area one which accept the result off the computation off area from a rectangle one. So I passed my variables length one and with one. Now the result is sold in area one, which can be now printed on I get the answer 24 which is eight times three. Similarly, I can have a variable area to on, then call this function with my second rectangle, which is length to and with two no on printing area to I get the result 40. So you learned how to write a function with para Meters and also you learned how to return values from a function. So that's the end of this lecture and the section on functions. Let's take a quick review off what we have learned in the section. So we started the section by discussing ward of function ISS, which is named block off reusable code that performs a specific dusk. And then we saw how to define the function. The syntax is to use the deaf given and then a function name followed by a pair of parenthesis. And then you have a colon with safe. There is a block off statement that follows your function. So an example is the hello world function which prints the statement. Hello world Then what we saw was how to make a function call. Now if you defined the function in order to call the function, all you have to do is use the function name with the pair of parenthesis. Then we learned how to pass Are humans too functions and return value from it. Now, in this example, we have two variables. Number one and number two, number one with the value 10 and number two with the value 20. So we have our function Find maximum to which we pass this para meters number one and number two. So to pass the perimeters, all we have to do is put in the parent. This is mentioned the valuable names separated by commas and then in your function definition you accept them in the same auto. So make sure that the order in which he passes the same when you passed number one and number two as the para meters receive it as number one and number two No, the names which you use can be different. But make sure that the order is the same and what we do in our function is to check if number one is great to the number two. If it is greater, we will return the greater number which is number one back to our main program else. What we will do is to return to the number two, which is greater than number one. And in our main program we have a valuable called greater number which will receive the number from the function, whichever is greater. So that's the end off the reveal on the section on functions. If you have any doubts so far? Feel free to use the discussion board and I'll help you from there. In the next lecture, we will be writing a program that implements functions and see you there. Thank you. 29. 12.3 Program - Find the greatest among two numbers: Hello and welcome to this lecture in this section you learned what the functions? No. Let's test your knowledge and functions by writing a python problem. So to do that, I start with opening a text editor. The van, which I use is Adam. And what program are we going to write? Our program would take two numbers as input from the user, and then we'll write the function that would check which among these two numbers is maximum . So let's first save this file. I'm saving. It does find maximum dot Levite. Now, in case you had missed any of the previous programming lectures dot be vie identifies your file as a fight on fire. So to get our problem statement right, it is to check which among the two numbers is maximum. So let's take input from the user. Let me give a prompt to the user to enter the first number which would be enter the first number. And now what we do we make use off the input function toe, take input from the user and store it and are valuable. Let me call are variable as first number. So first number equal toe input now if you remember the word input function does it takes input from the user in a string, form it? No. Since it is numbers that we're dealing with, we want this to be type casted into an integer. Let me do that to the second variable as well. Enter the second number and then let me typecast the second number into an intelligent. So now we have two numbers which we have taken as input from the user. So now let's go ahead and defined a function that would check which among the eastern numbers is maximum. Now. By convention, all the function definition goes to the beginning off your program. So let's do that At the beginning off my program, I defined my function and I call it Find maximum. Now. This has got nothing to do with the Finally you're finally manual function. Name can both be different. It's completely all right now what I want this function to do is take two para meters as input safe, first number and second number and then within the functions body. I want to check which among these two numbers are greater. So to do that I use in if condition which would check if my first number is greater than my second number. And if it is, I write a print statement that say's first number is greater now. The next condition that you can have is either your second number could be greater than the first number. All both your first number and second number could be equal. So let me first check else if my second number is greater than my first number. If it is greater, my print statement would be second number is greater now. The final condition which we have which can also be caught within else condition, is both the numbers being equal. So now we have defined our function body. Next, what we need to do is to call this function in our program. So in order to call the function, all that I have to do is to enter find maximum, which is the name off the function, and passed the para meters, which are the two numbers, first number and second number. Now let's save this file and executed to see what happens to execute my python program, I opened terminal. Now, if you're on Windows, you could use either publish L. Our command prompt. Linus users can use terminal as well. And now I enter. Fight on three and then I navigate to the location where my file is pleased, which is desktop slash Find maximum dot Be right now on execution. I need to enter my first number. Say I call my first number spent on the second number. Let it be 20. So I have my output as second number is greater. No, we could also have our function to return a value. So now, in order to do that, what we should do is to return the maximum number. So in this case, if my first number is greater, I would be returning the first number. If my second number is greater, I would be returning the second number. And when both the numbers are equal, I could return either the first or the second number since both are the same. Now, remember that when you return a number, you need a corresponding variable. That except so let me declare a valuable called us maximum number which will hold the value that is returned by this function. So if my first number is greater, my maximum number would be the first number. If my second number is greater, my maximum number would be the second number on. If both my first and second number are equal, my maximum number would be either first or second. In this case, I have taken first number No to print that print maximum number equal to let's print out the value this time. Now you don't remember that we can use a placeholder for the valuable name. A pair of curly braces stands for a placeholder and let's perform a string formatting and enter the valuable name as maximum number. Now let's save this file and executed one second to seawater output will look like no on execution. Let me give both the numbers as equal this time. So first number s 10 and second number s 10. So I get the output. Both the numbers are equal and maximum number equal to 10 which is the value returned by my function. So that's the end off this lecture. Go through all the pdf notes attached and solve every excess problem In case you're stuck. Feel free to use the discussion boat and I'll guide you from there the next section is on exception handling. We will be learning how exceptions are handling. Bite on. I'll see you there. Thank you. 30. 13. What is exception handling and how to handle exceptions in Python: Hello. You have now reached the last concept, which he will be learning as a part off this introduction course, and that is exception handling. So why is exception handling so important you might have come across the situation very well. Using an app on the AB abruptly closed on, you had no idea why. The reason that close was because some kind of an execution went wrong and that was not handled properly. No being a good programmer, you didn't want to do that. You would want to handle those exceptions, and that's when exception handling comes into picture. A simple example. What I can give you is the divide by zero exception. Now, if you are writing a program that both arms and mathematical operations on, there is a division that is happening on. If the user divide any number by zero, that problem would terminate without letting the user know what happened. Division by zero is an invalid division, and that's an exception which needs to be handled. So let's go ahead and see how to perform an exception. Handling and fight on. Let's get started by opening pythons Idol environment. So what is an exception? Say For example, you divide a number by zero. Division by zero is an in violent division, and that raises an exception. Now, being a good programmer, you would not want to raise such exceptions to your user. You need to make sure that exceptions like these are being handled. Buy it on, provides, try and accept blocks in which we can handle such exceptions. And how do they work? The block off court, which you feel might cause a problem, needs to go into your cry block on. The exceptions that are being caught needs to go into your except lock. Let's see how that works. So I have my try block in which I will have my block off coat. Say, for example, I have two variables length as 10 and my vet s zero. Now let me make a division off length by wit, which is stand by a zero, and it will raise an exception, so that needs to be handled in my except block. So how to define an extra block you enter the keyboard except along with the exception. Now, the wood exception, or rather the class exception handles all off your exceptions. Now we will be looking at how this can be a problem shortly. Let's see what happens now, so I'll go ahead and print division by zero this invalid. Kindly change your input right now. Let's see what happens on the execution off the strike block. They're not this output. It's much more need than my previous output, it say's the user. That division by zero was invalid. Kindly change a rent food than to have all those exception statements, which is raised by python. Now let's see how this exception can be a problem. See, for example, I haven't declared my reliable wit, So let me go ahead and delete my variable bit now if I try to access my valuable, but it raises an exception. No, If we go by the previous try block, which we had, which is to pry on, then divide my length by it and then raise the same exception. Let me just copy and paste this, since the exception is the same. So what happens in this case is the same exception is being raised, which is division by zero was in violet. Kindly change a rent put now. This is a long exception. The reason an exception was raised is because the valuable it was not defined. It was used before it was defined. But the prompt, which you're giving to the user, sees that division by zero was in Violet. Kindly change your input. So how do we handle such cases? You need to handle such exceptions by giving the name off the exception. Now, if you don't know what the name off the exception nous, take a look at the exception that was thrown by python. Can you see this name era here? That's the name off the exception. So instead, off using a generate term exception used this name off the exception. Now let's see how that works. So in my pride block, I have length divided by vet, and in my except Block, I give the name off the exception richest name Eddo, and within this, I print the statement. Variable has been used before defining it. Now let's see what happens. They're not. That message is much more better than the previous one, which misguided the user, this one clearly say's The variable has been used before defining it now, in case you wanted to use the divide by zero exception. You can take a look at what? That exception Waas. It was zero division ero. Now one pry block can have multiple exception statements. Let's dig the same example, but this time I will be changing the value off my bed. So let me reassigned the value of zero. And then what I do will be to raise an exception for my zero division error. Let me copy based it. So this is the name off the exception, which I'm trying to catch. So, as you can see under Van, try statement and having multiple except statements. Let's give a print statement in this which say's division by zero is invalid. Kindly change your input. No on execution. Off this try block. It clearly raises this exception. Betsy's division by zero was invalid. Kindly change a rent put. So that's the end of this lecture. You learned what is exception handling, and you learned about the try and accept statements and python. You looked at some off the except statement in python as well, so that brings an end to this section and to our learning off the scores. In the next section, we will be implementing a project based on all learnings that we have so far. I'm really excited to put into practical use off all the knowledge that we have gained so far. And I'll see you there. Thank you.