Practical Python Programming: Learn Python By Creating a Number Guessing Game | Minerva Singh | Skillshare

Playback Speed


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

Practical Python Programming: Learn Python By Creating a Number Guessing Game

teacher avatar Minerva Singh, Oxbridge Educated Scientist

Watch this class and thousands more

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

Watch this class and thousands more

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

Lessons in This Class

27 Lessons (3h 14m)
    • 1. Introduction to the Class

      6:45
    • 2. Install Python on Windows

      7:20
    • 3. Python installation on other OS

      3:15
    • 4. Working with Python Online

      3:14
    • 5. Instroduction to Microsoft Visual Studio Code Using Python

      8:11
    • 6. Basic Python Terms

      3:11
    • 7. Perform Basic Maths Operations in Python

      8:34
    • 8. Common Python Data Types

      3:46
    • 9. Generate Random Numbers in Python

      5:09
    • 10. Perform Operations on Strings

      18:55
    • 11. Get Input from Users

      5:52
    • 12. Tuple Operations

      9:04
    • 13. List Operations

      15:44
    • 14. Dictionary Operations

      10:33
    • 15. Define a Basic Function in Python

      7:44
    • 16. Create a More Advanced Function

      5:54
    • 17. Rationale Behind Looping

      3:40
    • 18. If-Else Loop

      8:03
    • 19. Elif Loop

      8:53
    • 20. While Loop

      4:12
    • 21. For Loop

      5:28
    • 22. More on Looping

      11:57
    • 23. Nested For Loop

      3:26
    • 24. Number Guessing Game-Basic

      6:22
    • 25. Number Guessing Game-Intermediate

      12:37
    • 26. Number Guessing Game-Advanced

      3:54
    • 27. Conclusion

      1:52
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

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

127

Students

--

Projects

About This Class

                Learn Hands-On Python Programming By Creating a Number Guessing Game

                              Beginners and Kids Can Now Learn Python the Fun and Easy Way 

Teach yourself (and your kids) to code in Python, the powerful programming language used at tech companies and in academia by working through an actual project. 

If you want to learn to code, building an actual Python project is the way to go !

I designed this programming course to be easily understood by absolute beginners and young people. We start with basic Python programming concepts. Reinforce the same by developing and enhancing a number guessing game. We will do this together, step-by-step

Why Python?

The Python coding language integrates well with other platforms – and runs on virtually all modern devices. If you’re new to coding, you can easily learn the basics in this fast and powerful coding environment. If you have experience with other computer languages, you’ll find Python simple and straightforward. This OSI-approved open-source language allows free use and distribution – even commercial distribution.

Can You Build a Career with Python?

Absolutely! On average, U.S. Python developers earn $109,000 per year. This powerful and widely-used language could be your or your child's ticket to a better life. With the rigorous grounding you get from this course, you’ll have the knowledge and confidence to step into higher-level Python courses.

Who Uses Python?

This course gives you a solid set of skills in one of today’s top programming languages. Today’s biggest companies (and smartest startups) use Python, including Google, Facebook, Instagram, Amazon, IBM, and NASA. Python is increasingly being used for scientific computations and data analysis. 

You Can Start Right Away, Without Prior Programming Experience

Detailed instructions have been provided with regards to Python installation and getting started with Microsoft Visual Code, a powerful programming IDLE that will be a valuable tool for your programming journey. Hands-on coding instructions have been provided in the lecture videos to enable you to follow along.. Each video will teach you a new practical programming concept that you can apply in real time and project building will reinforce your learning. 

The instructor is an Oxbridge trained researcher and always available to troubleshoot. 

Sign up for this course today and learn the skills you need to rub shoulders with today’s tech industry giants. 

Meet Your Teacher

Teacher Profile Image

Minerva Singh

Oxbridge Educated Scientist

Teacher

Hello. I am a PhD graduate from Cambridge University where I specialized in Tropical Ecology. I am also a Data Scientist on the side. As a part of my research I have to carry out extensive data analysis, including spatial data analysis.or this purpose I prefer to use a combination of freeware tools- R, QGIS and Python.I do most of my spatial data analysis work using R and QGIS. Apart from being free, these are very powerful tools for data visualization, processing and analysis. I also hold an MPhil degree in Geography and Environment from Oxford University. I have honed my statistical and data analysis skills through a number of MOOCs including The Analytics Edge (R based statistics and machine learning course offered by EdX), Statistical Learning (R based Machine Learning course offere... See full profile

Class Ratings

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

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

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

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

Transcripts

1. Introduction to the Class: Hello and welcome to my goes on project based fightin programming for kids and Bigness. And here we are going to learn biting programming in a hands on manner by creating games gu Ys and graphics. So before I dive into what discourses about, I'm going to introduce myself. I'm sure many off you know me already. I'm Renova on. I'm a PhD graduating tropical ecology from Cambridge University. I hold an M Phil in environmental sciences from Oxford. I have several years off experience in working with both fighting and are and doing practical programming. And it is essentially on the bases off my practical programming experience that I've developed this goals. You can always follow my updates on both Twitter and Facebook. Me never underscore data lab at Twitter and Minova Data lab on Facebook. And that's me by three. So what is this course about? Well, the course is about practical python programming on essentially, it is what it is, and I'm I seek to provide you with hands on step by step instructions regarding the basic fightin programming concepts and how to implement them. So the keyword over here is practical and we'll do keywords practical and hands on on. The upshot is that I focused very little on theory, just bare minimum. And the bulk of the focus is on equipping you to carry out practical programming tasks using python. And I always instruct my students in a hands on manner so that they can follow along or cold along. Specifically, I'm going to provide you with a robust, practical introduction to the most important and basic fightin programming concepts we are going to learn and, most importantly, reinforce the bespoke concepts by building games, graphics and grease and reinforced learning and especially practical reinforce. Learning is the most important thing that you could do, especially to master something like programming. And that is what this course is about, and that is how it is different from all the other courses on. We're going to do this over the course of 50 plus detailed lectures, plus a couple of quizzes to test your understanding. Specifically, we're going toe, develop a number guessing game, and we're going to move from just making a very basic number Guessing game, toe, a number guessing game, with more advanced functionalities using basic fightin programming concepts. So throughout the given section. I'm going to introduce you to the python programming concepts, loops it sector, and then we're going to actually, we've those together to build a number guessing game. We are going toe, learn to draw graphics, and we're going to move from geometric figures to growing irregular patterns using programming and not to put too fine a point on it. I would like you to watch this brief video and these are the kind of graphics you will be able to draw once you work through this course. Then finally, we are going to learn to design and launch functional grease, a graphic Jozic user interfaces, and we're going to learn to implement programming concepts to develop useful APS and learn about gui and user experience design while we are at it. So what will the scores do for you and as compared? And why should you think off taking this as opposed to the other courses? Well, the first thing is that I'm going to take the students without a prior background from a basic level to performing more advanced tests in python. And this includes developing a functional beytin based and project and water up. In addition, to developing beautiful graphics and building a number number guessing game. I'm going to introduce some of the most important programming concepts to students in a practical manner such that you may be able to apply these concepts for practical programming You will develop. You will gain a strong background in some of the most important programming concepts, and we will reinforce them as we develop games, squeeze and graphics together, lecture by lecture and every lecture is going toe. Either teach you a programming concept or reinforce a programming concept practically, and you will get a basic but robust exposure toe fight and gree development on a firm foundation to learn more advanced topics. Once you complete this course, there are only two requirements. You need to have an interest in programming, and if you can follow lectures three and seven off the scores and just get fighting installed on your system, then you're going to get started. Because throughout lecture three and seven, I talk you through biting installations, things like ID's. How do you go around checking your code online using the pipe, the online fightin programs it's across. So if you are able to do all of this, and if you are able to get a hanging off it and you have a functional copy off fighting on your system, you're good to get kickstarted. And by the way, let you do contains all the codes and the scripts that we have developed, wrote the scores and these scripts. They have been attached to the individual lectures as well, wherever relevant. Obviously, I would be grateful if you could share your feedback. If you have any difficulties, please contact me through messaging or the discussion board. I'm always around to help. Please let me know if you're interested in any other aspect of just such a statistical analyses machine learning math lab. I'm always I always dependent student feedback to develop more lectures and courses. And having said that, I suggest you move onto Python to download the script. And the lecture, due to download the scripts it sector and lecture three onwards, will instruct you in installing python on your system and actually getting extorted with it , because that can be a bit fiddly. All the best with the according adventure 2. Install Python on Windows: in this brief lecture, I'm going to show you how you can go about installing Python on your own system, and you can go to Google and put in fighting, download and essentially click this particular link, which will bring you toe this particular page. And since I'm going to be working on and demonstrating the code on Windows, I'm going toe download fighting for my Windows system. But of course, you can go and download biting for Mac if you like. And these are the fightin releases for the Mac operating system, and you should go right ahead and download the version most compatible for your own system . Now the question is whether you should install fighting 3.6 of Fighting Do Board seven. And indeed, there's an entire page devoted to this, this particular discussion and you can access it from here. Here's more about the difference between Python 213 For the purpose of this course, I'm mostly going to demonstrate the practical code examples in biting three. But I believe one should be familiar with some of the fightin to sin Texas, so one can essentially work with fighting to, because fighting to is still widely used, and there's far more documentation available for fightin to and fightin three. And essentially, the whole purpose of learning to program in fightin and using a hands on method is that you should be were as version agnostic as possible. So I mean, I have bought biting 2.7 and biting 3.6 installed on my system. And one basics impacts differences that if I want to print a word hello, I call the key word the fightin keyword print in both the cases. But the differences over here I just have semi coats for my word or string. It's formally known a string in fightin and say Print Hollow and Hello is printed for me if I want to do the same. In fighting 3.6, I have to put my hello, the string in apprentices. And there are many such differences between both relations. But up short is the way I troubleshoot across both the versions. You should be able to do the same, and by the end of the course, that is one thing you will be able to do. And so I'm going to work you mostly with fighting 3.6 and I'm going. And whenever possible, I'm goingto provide updates and imports regarding how the same thing can be done in fighting 2.7, but mostly for the purpose of this course, whichever version ur own. I mean, even if you are working with fighting 2.7 and you don't wish to install biting 3.6 for some reason, you're still good to go. And once you could complete the installation process, essentially, you download beytin and you carry out and you should follow all the steps, all the installation steps as it is. And once you do that, okay, and you should see something like an ideally should come up. So this is my ideally for quite angry and this is this is the ideally for 2.7. So, as you can see when I installed fighting 2.7, something known as an ideal eagles also installed and the same goes for fighting 3.6. There's an ideally installed for that, and this is the fight and shell or the interactive development environment for Piketon. So once you complete the process, you should be able to access the fight and shell either the 2.7 shell or the two point or the 3.6 shell, depending on the version you have about the versions. And this is baby type in interactive lease if I want to carry out. In addition, in 3.6, I look at these three barrels, three forward pointing arrows and they say, Multiply nine by nine and same for 2.7 and I'll get the same output here 81. And apart from that, both the ideally versions the potential versions they provide us with text editors. So we have text editors, and we can always carry out about analysis, carry out coding in these text editors, the default text editors and carry on saving the fight, saving our text files as fightin files. Dr B. Y files, See, And I'm going to show you where dot B y files look like so once you save. So once you type out your code in your fightin, ideally provided text file and save it as a doctor ey file. This is what we end up getting wherever you end up store, saving your coat dark P y files, and there's a Spuyten symbol next to it, which indicates that this is a heightened file and not a text file. And we can easily open this file through our shell, the pipe and shell, and run a bar code again. The other things that I'm going toe cover further own in this section. But by now, you should certainly have fighting 3.61 installed on your system by following that the fourth Command. So just download and follow all the steps as it is. And once you do that on a Windows system, you should have access to this ideally, and you can even search for it by typing in fightin like so. And that brings up the ideally programs for both biting 3.6 and 2.7 in my case. So you can click on these and essentially, this is how and where we end up writing and working with our bite bite and programs. And obviously there are much better looking idea leaves available, and I'm going to discuss that as well for their own in this section 3. Python installation on other OS: Okay, So while I'm going to demonstrate this course on a Windows based laptop, biting is language. Ignore is black form Ignore streak. And yes, you can installed bison on UNIX, Mac Ox and other operating systems. And it's just a question of say, if you want to install your python on Mac Ox, it's just a question of going to this page. Downloads Macaca, Mac or Sex and installing and downloading the installer for which is compatible for your system. And the latest release is the Fightin 3.6 point two. I'm going to be demonstrating all my code in fight and 3.6 point one. But these are not drastically different from each other, so you can go right ahead and either install 3.6 point one or 3.6 point two. And in case you have one of the older versions of fightin fighting to on your system and I'm going to be guiding you through the variations between Python two and three, and these are just some this is some information pertaining toe using fightin on Macintosh and these this information has been provided by Doc Stark fight and using Matt on essentially, when you download Matt for your system, Well, if you are on 10.8, then you have fighting 2.7 in the pre installed by Apple. And yes, you have the option off reinstalling, fightin three from the website and the mat bite and 3.64 level being your applications folder. And the software, it seems, comes with the ideally on. And essentially, you can go right ahead and read up all of this. Or you can just go and start installing the fightin on your Mac based operating system of the UNIX system and then following the normal way that you fire up programs for the first time. You can fire a program, and it's not the Fightin program. And firing up Iten and getting started with fighting in an interactive mode or using the inbuilt ideally, is not very difficult. After you complete installing, basically, you should be able to access the bite and 3.6 point one shell or whichever beytin you have . And this is the interactive fightin, and they should not be too difficult. Additionally, you also have the option off installing fightin with raspberry by in case you have a rest very by and all the details they have been provided over here and in guess you do get stuck with fighting installation on your own systems. Then you can always drop me a message, and I'll be happy to help. 4. Working with Python Online: in this lecture, I will quickly introduce you toe online bison idee, ease that we can use it. We're just testing code and testing snippets off code because, you know, there are so many times when I don't feel like firing up the in DI a bite and system on in that situation, it just makes sense that I test my gold or snippets off court in an on online bite, an I. D E E. And there are three of those that I can recommend. And I have pro provided the links to these in the resources section of this lecture, and the 1st 1 is heightened fiddle dot com. So if you just type the sini in your browser, you should come toe a page like this. And then there's this one by tutorials point. And then finally there is the Fightin Interpreter own line fighting Interpreter by Matt CS , and it's a complicated one, and as you can see, they have provided us with some sample code, and this is not a complete version off fightin, but in case it, if you want to test out bits and bobs of code, I think this is pretty decent So let's just run the default goat se print. And there this is it gives an output. Hello, world pick a number and so on And seem for this we just press execute and it does us Hello world, the most common fighting program we seem to be starting with. Now I have some cold written with me, and it's just testing. If in else conditionalities, in case the court doesn't make sense to you, Don't worry, That's the nothing that we are going to start covering in the future. But let me just copy paste this thing in biting fiddle because I really like biting fiddle . And obviously all the Indians have been copied in and so so on and would run it. And as you can see, I get the response big. Essentially, I'm just besting. If my ex is Greer is less than equal to five, which it is not. And if it is not, then we print pig. So it prints big for me and I can do the same here different and execute big and same here big, so beytin online pipes and ideas. They do come quite handy, owning often, especially when we want to just quickly tryout with bits and Bobs of Gold and the other three biting online beytin interpreters that I recommend for a quick bite and go testing. 5. Instroduction to Microsoft Visual Studio Code Using Python: Okay, by now, you should have fightin and hopefully bite and three installed on your system. You be it a Mac, albeit Windows. You are acquainted with the python shell, and I have introduced you to do a integrated development environment. You know, the text editor that is provided within fightin and where you can type out your code. And also for Windows, there's another I D i D e. The note Bad plus plus, which just allows you toe produce more intuitive code. Not up short is whether you use the fightin I d. The fightin inbuilt text editor, or you use something like Note bad. Plus, you still have to run your code through the fightin shell, and there's no problem with that. But I've come across something known as the visual studio code so you can go to Google now if you haven't done so and type in visual studio code. This is the source code editor developed by Microsoft and unlike Note Bad plus, which is only available for Windows visual studio code is platform Ignore Stick, which means it's available for Windows, Lennox and Mac. You do need Mac 10.9 plus, although there are some earlier versions available. You can search for that on Internet, and you can download visual studio code and install it as it is. And this is my copy off the visual studio code. And what it lets me do is I can type out code. I mean, I can actually create a heightened file in my given folder. I am working in a given folder right now, and this is my folder, and it has to dot b y files. I can create a fightin file right now, right here within my visual studio code like so. And let's just give it in the name. So if I f c three dot b y and it has been created for me and I'm actually going to copy paste this if good over here and let's just save it, it's been saved. And now I'm going to, right click this and I'm going to run the fight and filing terminal. And as you can see, it's given me the output small over here. But how does this thing you and work? I mean essentially, which will studio code off with us that one page of being platform Agnos trick and allowing us to run about code straight from the I D or the source school called editor. Basically, we can run our court straight from the editor, and we don't need tohave the fight and shall opened up. But in orderto make visual studio court the way it's working for me, you need to have fightin installed on your system. Then you can download visual studio code, install it on your system, and this is what the symbol looks like. And once you've done that, we go to extensions, and this is a symbol for extension. And because visual studio code it's not really it's not just restricted toe fight and you can work on JavaScript. Oh, it supports a large number of languages, so you need to go to extensions. And if you don't see this particular symbol on this bar, then you can go toe. You can press control shift X if you're on a Windows system, or you can press this command X up key on a Mac and bring up the extensions. Essentially, once you bring up the extension and I'll bring up my extensions. I do have fighting and fighting for Bs gold installed on my visual on my version of visual studio code, And that's why I'm able to run beytin straight from my source code editor. But you'll have toe search for extensions in marketplace and actually install these. And it's quite simple. Say, I want to install JavaScript next, So I'm going to bring up JavaScript and I'm goingto press in start, and once it's installed on my system, then I should be able to run JavaScript code from the same. But actually, I don't need that. So you'll have to type in fighting and install both beytin and fighting for we s gold on your system. And once that's done, the install button will go away and you will be able to run your fightin code straight from your source scored editor. And they should work both for Windows and Mac and what we do. Once all of this is installed, we work from folder, so I'm based in a given folder scripts and essentially, you see another doctor ey file was created from me within my visual studio. Suppose I want to work in this folder, so I'm going to actually open a 40 gun and select fightin scripts that was the name off. My folder is going to load up now. My folder has been loaded up for me and see, you can just ignore it. Disabled this letter. We won't be needing it. So that's that. And this is my temple. One word one dot Be why I'm trying to convert sudden height in tow. Self. I'm trying to convert sell shares into Fahrenheit. So let me just run this run bite and filing terminal. Uh, because I have heightened three at Bagram would work with biting three. I need to have the parenthesis like so And it does tell me that okay, now gone wrong. And this is what I need to do. And let's just see, Okay, Actually, this is a bit bugged up, so let's just run this one. And this lets me run the fightin cold. Hello, Kitty Straight here and we can see the output. And I can even run my if gold here if else. And because X is greater than eight, I get big because eight is greater than five. I get big and essentially This is how we run different codes. Different fightin scripts. You straight from visual studio code and the way I ran into problems with my previous code . It also tells me what exactly has gone wrong and I can de bucket I can use this debug editor, or I can reexamine my cold manually and essentially run my scripts straight from the visual studio coat. And for most of the scores, I'm going to work with visual studio coat. And obviously, if visual studio code doesn't work for you or you prefer different I D or you prefer note pad. Plus, if you're on Windows, then I believe you should be able to do that. Do that and you can follow along. So with this, we are actually right, ready to start with the actual nuts and bolts of python programming all the best. 6. Basic Python Terms: in this lecture, I'm going to introduce you to some common fightin keyboards that you should be familiar with, and these are something that we are going to work with. A fair bet throughout this course. And let's start with this biting module Models and Buyten's are simply bite and filed with the doctor. He by extension, and these implement a set of functions. More duels are imported using the import command now on the topic of functions biting functions. These are either user defying the in built, and we're going to explore both of these in greater detail, further own in the course the performer given task or have a functionality example. Print statement is an inbuilt bite and function that prints and output. Then we have something known as beytin packages, and a package is a collection off models in directories that have a given hierarchy. It can be imported using keyword import, all using the from keyword example from X import. Why, and we're going to work a fair bit with fighting packages and one bite and inbuilt fighting package that we will work with the pink Iturbe Aiken fighting package for GUI programming, and that's going to come for the one in the course. Now on the topic off keywords, keywords are reserved words. You know, things like import from these are reserved words that we can only use in a specific context . So we can't just use these words randomly. Let us just see a practical example. So I've used the keyboard import import to keep to import the module keyword, and this module contains the list off key words that are present with heightened 3.6 point one. So as soon as I use the function print to print the keyword list, it prints There's for me. So falls none, and deaf and live Lambda exactly are These are all fightin keepers, and the reserved for certain tasks on import is how we end up importing both models and packages to work with beytin. And it is these modules and packages that give an additional layer off functionality and power toe fightin. Fighting has a lot off inbuilt functions in built models and packages, and we're going to work a fair bit with the inbuilt module and packages. And there's also the possibility off installing third party part packages and models. But for a basic course. We don't need all that. And then we can even get help about the building. And you can see that we have a rich collection off building modules within beytin. So these other things that we are going to explore further own in this course 7. Perform Basic Maths Operations in Python: before we move on to doing formalized data science in Beytin, I'm going to introduce you to some of the basic mathematical operations that we can carry out in fighting. On up short is that this is the basis of carrying out any mathematical operation in fighting. Say we have two plus up to numbers. We will say Value plus value, where plus is an operator. So we use mathematical operators. Things like the plus sign, the negative sign, the multiplication sign, the division sign and so on toe carry out mathematical operations between two or more numbers, and I'm going to quickly demonstrate some off these. They're very simple and we're going to be using them a little bit in this course. I'm going to carry out the demonstration in the fight and shell itself because, frankly, this is really quite simple. It's just a way off introducing you to some of the mathematical abilities off pythons say I want to plus up to numbers nine plus eight. So I'm just going to put in my two numbers nine plus eight and the plus sign is between them and I get the answer. 17. Suppose I want to subtract nine miners states. So my values are nine and eight and the operator is negative and I get one. Suppose I want to multiply these two numbers so it's nine and eight and you can see over here I'm going to put in the ass. Tricks between my values and my operator is the ass tricks for multiplication. And it is 72 now. If I want to divide, say, nine by nine, I will get the value one and let us see nine by eight again, I get the Valley one. So all a few people who are working in fightin 2.7 plus nine divided by eight it will carry out something known as an integer division. So I will not get the decimal numbers that should come after one, and that's inaccurate. So in order to get that, I will have to specify float. And now this is a data type that allows decimal numbers to be presented as well, and I get 1.1 to 5 and off course. If you have not heard about in teachers and float, nobody don't other things that were going toe cover very shortly. But this is just to introduce you to some of the mathematical capabilities. We can even get the remainder by using the percent eight sign and which is the Montillo. And we get the remainder like this. In addition to some of these basic mathematical operations, we may want to take things like square root. For that. We have toe import a module called Import Matt. And there I can put in Matt, which is the package that I've imported. Matt is the package of imported. Hence I put Matt docked the function name, which is the square root, and this is going to be nine, and I get the value 3.0. Of course, if you want to carry out more detailed computations than you can explore some other functions provided by Matt and massive a fairly powerful package for carrying out a wide variety of automatic operations. Suppose we want to take out something like an exponent, you know, for a raise to power to a 16. So let's just do that here. In this case, my operator is going to be two ass tricks which mean that this is an exponent, which is four days to power two and just to point out where every time when you get a number like 3.0, that's the float. And if you get 16 and there's no point in front of it, this is an in teacher. Another way to do this is to call the function P. O W, which is power for the number on the power. I want to raise it to the public off two. And essentially, this is another way off taking an exponent. In addition to this, we even have some comparison operators. So say if I want to compare, one is greater than do it will tell meters Faults and comparisons are things that were going to use further on in this course. So this is something you should be acquainted with. But as you see, we just have a handful of comparison kind of operator that we end up using. So these are not too complicated. Basically, again, it is false because it is neither greater than north in or is it equal to nine and so on, and this is how we carry out the comparisons. The most important thing that I want to introduce you to here is something known as a very able right now. I have been typing in these values other days. But when we carry on working with proper fighting kind off programming, it is difficult to just go on refering to these values like nine and eight. And then we create boxes to store these values, and so are variable is the box that stores a given value. So if I put in A is equal to nine B is a called toe, eight C is equal to a toe be and now I can print in order to get the value. See, I'm going to call the function print and it tells me to 72. Now I can even change the values off my variable. So if I declare my very able to be eight and in this case, I'm going to use equal 12 an assignment sign and now if I carry out the same operation. So essentially I just have to declare a given set of variables ones once, and they become my container so things like ABC become my container, but I can go on changing the underlying values there in Onda. We are going to be working a lot with variables now on, there are different variable, normal nature patterns. I mean, if you don't like the idea of saying ABC, then we can use Camel case. We start out by small letters and say my where and say 90. This is a camel case because we started out with small letters followed by a capital letter , and this is a very good way off naming your variable. And it just makes things a bit easier as we start working with a lot off Variables 100 and when I put a hash, this is a comment. So basically, this thing is not going to be process, and this is what I'm going to put for my own knowledge. This is going to say print, but essentially the value of C has been printed. But print is not not going to be processed. And I can just put in these comments symbolized by this hash as a way off, reminding me what I have done and so on. And in this brief lecture. Now you've been acquainted with a wide variety of mathematical and comparison type off operators and, frankly, the pretty straightforward and I hope you have been typing in all of this stuff as I was typing along on my screen. And if things are still not clear, the other things that are going to become clear and these other things that were going to be working with a fair bit in their score. So things are going to become clearer as we go for the on in the course. But right now I'm going to move on to the next lecture, and I'm going to introduce you to the different data types that we end up having in fightin . And you have been acquainted with some off the bespoke data types in this lecture itself. 8. Common Python Data Types: in this lecture, I'm going to briefly introduce you to some of the most common biting data types that we are going toe encounter while working through the schools. There are other data types, but the three D data types over here that just about the most common data types that one needs to be familiar with, and the 1st 1 is in teachers. This refers to whole numbers, such as 8 10 11 Second is float. This refers to floating point real numbers such as 9.2. So while impeaches can only behold whole numbers floats, it includes decimals like 9.2 string. It refers to words and is encased in double courts things like Cat. Or even if we put a number within double coats, that becomes a string. So I'll just quickly take you through these so invariable end I have put in four, and since this doesn't have any decimals associated with it, it is actually an anti jersey. When I printed out it's type and type, it tells us type of an object. It just tells us that what the type is in in terms off the data type that it belongs to and this is an inbuilt fight and function and I can print it out. It say that it is int. Then I created a variable float and in that I have put in 7.8, which is a really number, and when I take out the print, it tells the type off. When I print outed, Stipe tells me to the float in str one I have catched within double coats and the type is string. And as soon as I put in eight within double courts, that too becomes a string. And now since my interest is equal to four, I can even convert it toe afloat. So this is this is an integer and I cant converted toe afloat. - So now we have in teacher, which is four. And when I printed Stipe, it tells me it is an end. But when I print the type after putting in float, basically what I have done is I have converted the variable within the brackets into float by calling the function float and the variable instead off X, my variable is end because that stores the data value off four and and these are just about some of the most common data types that we are going to carry on working throughout the score. So now, in case So these are the three things that you should remember and in case exactly a in your mind, then we're good to go on further. 9. Generate Random Numbers in Python: Now that you have been acquainted with some of the most basic data types and python in this lecture, I'm going to show you how we can generate random in teaches between a given set off in teaches. And by that I mean, how do we go about generating random whole numbers? And being able to generate random whole numbers is fairly important and useful because there are times when we do need to generate random numbers, say, in certain games, or even for complicated mathematical simulations? No, we can't generate random numbers just like that. We have toe import a package called Random On, and this is an inbuilt bison package. And as you can read the documentation, it is a random variable generator and in teachers are generated within a given range. And how it does that, you know, using something known as the guy ocean or the log normal distributions. This is not something that we really need to know about. But the upshot is that this package will help us generate random anti jizz. Now, once we import the package, I've declared a variable called day one. I'm going toe call random dot ran it and rand. It is a function on. It will return a random in teacher in the range a Toby and include both the end point. So in this case, I want to generate a random in teacher between 1 to 6, and it can return a value which is greater than or equal to one or less than or equal to six. So let me just run this goat, Okay? So the entire court has been run. But if you just look at the first number, the first number corresponds to the very able die one. And in this case it has generated five, which comes between one and six. And now, after I ran the script again, the first number over here is four, which is again between one and six. But obviously it's not five. Unless just with the third time again, I get a five. A number between one and six. Now what happens when I want toe return a value greater than or equal to X, but less than why? So I'm going to call random essentially random got rand range and rand range is going toe. Choose a random item from a given range and essentially it will choose numbers between one and six. But whatever numbers are chosen, they will always be less than six. So let's just run it. Run Patton. It will choose numbers from 0 to 6 because all specified six. But essentially it will always be less than six. And there we have three, which comes from die one which corresponds to variable divine. And for day two, we get full between again less than six. Now, the thing about trend range is that it also allows us to specify a step. And essentially, if you just read how this function has been constructed in Fife in. So we have stopped and we can specify step and by default the step is one. But actually, in this case, I want to generate numbers between 1 to 8, always less than eight and using a step off doof. So let's just run this gold again. So there we get for die one, we get 34 and then we get five for die three and this is between one and eight. And if we take the step function from one, then this is an old number and again another order number because Essentially, we are taking a step off to from one which is an old number. And that is why we get values like three and five and so on. And these are just some of the ways that we can use the random package to generate random numbers for us. Between a given range off in teaches are whole numbers, and this is something we are going to use further own. In this course. I have mentioned the word functions a few times and you can see that something like Rand and even inbuilt fightin function. We are also going toe work on building our own functions. But that too, is further on in this course. So I hope you've been able to follow everything so far. And now we're going to start getting into actually using bison toe work with more complicated data and structures and patterns, and that starts from the section onwards 10. Perform Operations on Strings: in this lecture, I'm going to talk you through working with strings in bison and all the code is here. And while I'm going to talk you through all the court that I have written in here, we're also going to make things a bit interactive. And I'm also going to work on this online by turn Interpreter and I have already introduced you toe online beytin interpreters, and they're very good for impromptu coding and for testing out called snippets. So whenever I feel that there are things that you should be thinking about before I tell you the solution, we will switch to the Python interpreter on all the code will be at your disposal. So I have this string and basically in fightin. When we declare a string we declared within goats, inverted coats or single coats, that doesn't matter. I prefer double coats and anything inside in inside. Thes Coates is a string, and strings are basically immutable. So once that declared that declared, and you can actually even read about the details off strings. And that's one good thing about using the visual studio code, and but I'm going to actually start examining these so str one stores an entire string a sentence within Coates thing Hello I have a cat I would've based and let us see if if it's actually a string So now if I want to check out if a given variable because I am storing my sentence Hello I have a cat invariable str a one But now how do I check and what should I type in in our in order to see what type my variable is right type Okay. And now this is plus string str and class str is an inbuilt biting class which is used to the present strings and it has a number of functions off its own And those other things that were going toe cover in this lecture and let us I put in a number eight is an integer if you recall But if I run it here, it shows me the same thing. The class is still a string and if I remove these goats, men and run, then the class becomes an end which is an inbuilt fighting class alluding toe in Tages. So essentially, this is the difference between in tages and strings and every time you see anything that's enclosed within double coats, that entity becomes a string. So I'm going to copy in the two strings that I'm going to be working with. And String three or variable SDR three tells us that my God, she has short hair. Now what happens if I want Tokcan? Captain ate my strings, or I want basically all of both of these to be combined to read one single sentence. Right? In that case, I'm going to do print str one plus str three And okay, it's running the whole thing for me. That's the only thing I don't like about working with I. D. E s. Because end up running the whole cold for you. But then we have heightened interpreters to examine our entire code one by one. So there we are. So hello. I have a cat. She is a short hair. Now what happens is that I do have spaces between hello, comma and I. But I do not have any spaces between cat full stop and she and what happened if I want spaces between my two strings Well, what I've done over here is concocted nation and I have already return it over here that this is how we can captain eight strings. So let's just see what I do now. I'm going to put a space here with a space here. Single quotation space there. Now we get space between the cat full stop on the capital s of the she and this is how we essentially end up creating spaces between strings. And you can also you can see that here Another way of doing this is to use join. And this is a fight and inbuilt bite and function join and essentially, it returned the string, which is the concatenation off the strings in question and concatenation of these strings s Tijuana and str three or rather, the strings contained within variables Esti a one an SDR three. So let's just try this. So I mean, I am going to get the same result. Let's just put in a full stop and then see there. So now you can see that this code actually ran, and when you run it yourself, you will see that this run and this is how we use an inbuilt python function joined to join two strings together. And there are other string operations that we can carry out. But first, let's find out how long is my string, or how long is this particular sentence. So every time you are going to see print, because I do have to call print in order to show my output. If I don't call print, there will be no output to show. But so you can ignore that or just take it as an exhume. The important thing is that I'm going to use the function Len, and that is going to tell me how long, my stringers. So let's just hope for Len is an inbuilt beytin function which returns the number of items in a container. So in this case, my variable str one it stores my string, which in turn comprises off a number off letters and those letters they came together to form an English language sentence. Now fighting doesn't care about that. I could very easily use variable str one to store an Indonesian language sentence, but and those would be a number off Roman words Roman letters strung up together. And so that is what Len is going to do. It is just going to return the number off letters in the variable str one and letters and spaces between them and the full stops anything that are stolen variable esti a one will be returned and obviously you know about print. That's an inbuilt fightin function toe print out my output. So where this is the length off my string. So the sentence stored invariable esti a one is basically comprises off 20 characters. You know the letters a full stop and the spaces put together. All of them are 20. And that is very important because what happens if I want to print the first letter off String one And indexing and sub setting strings is a very important family off string operations that you should know about and the other Tarak tickle underpinnings and which is that assume this is a variable str storing this particular string. So the fightin index starts from zero left to right. So by that I mean the first letter that my very my variable stores Capital H is actually at index zero e that index one and so on. So in this way, if we have a variable with stores this string, then it be that index zero r it index one and so on. And if we want to use negative in, this is then depending on the length off the string, the negative off that value is going to be the first index or index zero basically, and all of this will become clear and then if we want, if we move from stock toe end so the end index is usually end minus one. If I just specify a starting index, we move from that particular index number all the way to the end. This is how we copy a string and dark end. This will give us items from beginning off the string toe end minus one. And don't worry, we are going to work through this. It feels funny to everyone. And that's one reason why I'm putting so much emphasis on according interactive Leah as well. So no, If I want to print the first letter off str one based on this based on this, I'm going to actually alludes to zero and I get the H capital age. Actually, if you remember the previous code, the total length off this variable esti a one is 20. So if I want to refer Toa h I can even se minus two and b and SD a one square brackets minus 20. And I get the same value minus 19 Will give me Smalley because h that index zero if I look at the positive and this is an index minus 20 if I look at the negative, induces going up to minus 19 minus 18 and so on. So now I want to isolate. Hello. How would I do that? As you see Hello. It's stocks at zero h stocks and zero and zero ends at the O and that full. Now what should I do? And I'm going to the first start toe end some. My starting index will be zero because that's where my H is. But what should What should be my ending index. Okay, here goes, and it's Hello. So 0 to 5 because my zero and that index four. That's why I specify index five, because it's going to print out five minus one basically, and that's going to be the final thing that that gets printed out so and seem. If I want to print out I have a cat, then my full stop is that Index six. The space is that in next seven. And actually I can just start from here and it's going to go all the way to the end. I have a cat starting from here toe. I have a cat. And if I do this, then it gives me a hello with a period. And this is because I start from zero and go all the way to six, which is seven minus one. And this is what I had already shown you before and let me just And this is how we copy a string that this is the new variable. I want to copy my str one contents into S t A. One contains the string square brackets go alone within the square brackets and I run Well , I won't see anything right now because I'm not. You have not used the function print, which I should and that Hello. I have a cat and I can even convert a given set off letters into capital. And let me just run this gold piece by piece to show you how so I'm going toe store my hello In another variable called high and you can see that and I'm gonna do actually Let's just run that bit. So hello is stored in variable high and I'm going to call Dr Upper The function dark upper on the variable storing hello and I get capital. Hello. And if I want, you can work uppercase into lower case than my function that I use will be lower. So basically, this is what this inbuilt function does. I can even split according toe white space and I just explain what that means. So I have this entire string which is basically a sentence. And now if I call the function split the inbuilt biting functions plate is going to split it as hello and because white space means space. So then I then space and that's another chunk have. And essentially, these are some things that one should be acquainted with. And what I am doing right now is just touching upon some of the basic functionalities that you should know about. And if you get a handle on these and I would urge you to practice what I have talked to you in this lecture once or twice, then you will be able to tackle more at once to string processing in the future and then I'll come to the final function, which is to replace now my str one a. Basically it say's Hello, I have a cat from what happens if I want to replace Cat with the black Cat. Then I'm going toe call the inbuilt fighting function replace And that's one good thing about these i de ese interactive development in environments that they tell you what even bill pants, fight and functions are all about. And so what I can do is to replace old the old word with the new would in this case. So you can see cat is the old word, and I want to replace it with new, which is black cat. And obviously, depending on what you want to do with your string, you can do something similar. So now it's a it's my sentences. Hello, I have a black get, and essentially these are some of the most important string operations that one should be familiar with and engage these things. They feel slightly confusing. I would suggest that you run this gold again and maybe put in some other sentences within your string variables and then try to see what the output will be 11. Get Input from Users: okay, in this lecture, I'm going toe show you how we can except inputs from users and store them in our way. Variables on and them syntax for doing so is different for fightin to and bite. And three. So right now I'm in bite and three and I'm working with my visual studio code. So by default, this is running pipes and three. And if I want to get imports from my users to store in the variable var, then I use this particular fight and keyword in port. And what this does is that this particular, this is an inbuilt bite and function, and it reads a string from standard input. And essentially, the very same input that we put in is printed on the terminal. And I'm going to show you how so, Essentially, by calling the function input, I prompt the user on the terminal toe, enter an input which is printed out using the function print. And so let us just run this goat. So hello. What is your name? Joe. They're so this way. I was prompted to enter my name and where once I did, Joe, this was printed out like here. So in case off by phone do instead off the function input. We use low underscore input to get the input from the user. So, flu over here I had input. I used a function in foot. But now if you are working with fightin too, then you are going to use row Underscore input which in turn is going to prompt the user toe provide you with provide you with an input which is then printed out Selections do this as well. Someone to run this run module. Hello. What is your name and their This is how my my name has beaten typed out on the demo on the in the bite and shell. And first this particular string was printed out and I was prompted to enter my name, which I did and thus the printing out. So this is the only difference between when we're working with heightened to invite and three. But actually let us see what happens when we start working with numbers. So now if you remember, when I put in type essentially type, it tells me what type off, essentially the type off my variable in this case very ableto. And we've already seen this. So I'm going to somewhere to put in a number on the class off my Web, where two is string. Because even if I enter a number through the function in port, these imports are regarded as strings by default. So Intergovernmental Finder a number like eight or I enter cat. It's always going to be a string by default. So if I want toe intern in teacher and there might be cases that we're going to look for their own when we want to enter a number, say, an in teacher or maybe even a float directly and what we can do is to call the function in port, put in a number, but essentially convert our string to Annan teacher by putting in int right in the front and enclosing it within brackets. If you recall we did something similar in the previous lecture been we converted an integer to float Well, the same rationale applies here, but now we're converting a string two in picture by putting an end over here on the brackets here like so. So that's so put in a number eight and the classes int on. That is because I converted my string to an integer the way I'd converted an integer toe afloat previously. And this is how I can enter a number directly into my variable three. From on the number will be provided by the user. So far, we have been discussing out the different times off data that the variables can store on. We've also discussed what variables are and so on. No. Over the course of the next couple of lectures, I'm going toe talk more about data structures. You know what happens when we want to store more than one number? Because variable that can only take one input. You know, it can take one input, say cat or it can stay. Stole one number. But what happened if I want to store five numbers or five different species off animals? In that case, we're going to use the fight and data structures, and that is what I'm going to cover for the own in this section. 12. Tuple Operations: okay. In this lecture, I'm going toe briefly. Introduce you toe a very common and one of the simplest data structures out there, known as Stupples or two pearls on. This is the simplest container for storing more than one variable. A couple can store strings in Tages Auriol numbers we created using round brackets. This is immensely important because the other data structures that we are going toe cover in this section are created by using different brackets. The most important thing about pupils is that they cannot be modified once created. So when we have variables and say we import one single value say X is equal to four, we have the option off saying, you know X is equal to five and the value off four is replaced with five. But we can't do that with pupils. There are a few operations that we can still do with pupils, So I'm going toe cover Stupples. Now, by the way, for the time being, I'm going to work a little bit with the online fightin interpreter, and you can fire up a beytin interpreter off your own choice. Or you can carry on working with your desktop fightin Ideally, that's entirely up to you. I just feel it's a good idea to be acquainted with by 10 interpreters as well, and they are rather effective for more interactive and impromptu to coding. I'm going to stole my to pull in a variable called My Topol with a camel case. By that I mean my is small and the t of the two police capital round brackets. - So my Topol has been printed, and it comprises off strings off a single character and an integer in a while. It's use Agent functionalities rather limited, but I can always add, say, another character to my do pool. - So this is my new and updated my Topol, too, and I've added a character G to it. I can even add an integer. I mean, I can replace my G with an integer, but obviously I will have to put in a number without the invited coats and a comma. After that. In a couple, I can query the location off the different items and just remember in fightin, the index starts from zero left to right. So in my Topol the item, the first item we see is actually index zero I'm going to be explaining and bringing up this index principle a fair bit in this score. So this is something that you should keep in mind, and I'm going to bring it up again and again, so the idea is reinforced. But right now, let's just go back to the Brighton interpreter, and I do hope you have been coding along with me. So let's go back and try out some indexing. - So the first item off my Topol to Waas and to be one on if I want to print that out and just that one out, then I call my to pull my Topol to square brackets and zero and zero refers to the index where the index that I want to print out and what it will do is to print out the actual item at the base spoke index and let's just do it for, say, index to So it has chronology. It has printed out three, and in the chronological order three is the third item we see. But from the pie tin index point of view, the item three is that index, too. Hence three has been printed out. I can even see what particular index a given item has. So let's just check that. And before that, I'm going to actually check the length off my Topol. - Since I have six items in my Topol number, six has been printed out. And now if I want to do more at once, things like wedding, what exactly is at a given index or replace value at a given index and so on? For that, I really can't use a triple for that. We have another data structure known as lists, and that's what we are going toe cover next. So in the next lecture, I will continue to work with this online by 10 interpreter and I'm going toe introduce you to a far more flexible data structure known as list. 13. List Operations: in this lecture, I'm going to introduce you to a very important pipes and data structure known as a list. Fighting list is basically a collection off items, and it can store different data types, including in tages and Strings and introduce and strings that can be stored together in the same list. Fighting lists can be modified and lists are declared using square brackets like So Now let's just assume that this is a fight and list and we have be as our first item followed by are followed by O and the the individual items stored in the container called Lest the Fightin Index starts from zero moving from left to right and in case we want to use negative induces, then the negative of the largest numbers and negative index and decreasing as we move a left to right. And it is important to remember the Spuyten indexing scheme because there are times when we may have to isolate given portions off the list. And these are some of the things that we are going toe work with in the rest of this lecture, and I'm going to work in a bite. An interpreter, one of the online bite and interpreters I had spoken about. And if you like, you can work with any online beytin interpreter off your choice, or you can even carry on working with your desktop based Ideally, that just depends on what you want to do for me. You know, fighting interpreters online ones are a quick way off testing gold and introducing myself to different gold snippets. So let me just start out by creating a string based list, and I would recommend, irrespective off the system that you use. You type along the cold as I type it on the screen. So let's just have I do need toe print out the variable with stores my list. So this is my list, which had declared using square brackets. It comprises off four string items, and the bespoke list has been stored in the very able called M food. And if I want to see the out Bert, then I will have to print the variable M food. And before I do that, actually, let me just create a numerical list as well again square brackets. So when I run it both the lists they have been printed out in the output. And as I mentioned, we can have a mixed list comprising of both strings and numbers. So let's have mixed list now. Just call it, give it the variable name makes square brackets again, and that's happy. When I declare string I adoption off either using single courts or double courts. That's not a problem again. I do need to print out the variable storing my mixed list, and it has been printed out like So Now I can even fast a list in a given list. Square brackets again. No, I'm going to passing this particular list. This numerical list that we created before on it has been stored in the variable and know s some go to say in us, and I'm going to print this thing out. And as you can see, the list that was printed out this fourth list it contains another list, and this another list are basically the variables present in the list and no s. And it has been included as another list item. And these are some of the ways and off creating lists with either strings or numbers or both, or even with other lists. Now I'm going to give you 30 old seconds and make sure you type out and run all of this gold. And after that, I'm going to quickly show you how to create a list from the scratch. Okay, so now, now I'm going to create a list. I'm going to declare an empty list. So when I put in these two square brackets and there's nothing in between, this is an empty list. No, If I want to add a contact, then I'm going toe call the variable name in which I've stored my empty list, which is contact docked, append. The function upend off. Fightin is going toe upend something that I want upended in my list. Let's just say I'm on to upend the name often individual. So now I have a list. I created an empty list with dot upend. I've added Gary to my list. I can do that with but another item. Another string based item. And as you can see now, my list. It contains two string items Gary and Mary and I've added both of them to the previously empty list stored invariable contact by using dot upend, and you can do the same that upend is not the only way off adding more items to a list. Say we want to add several items to a list and let's just do it in one go. So I'm going to actually put in contact basically the list name where I want to add all off this information contact, extend round brackets. And now I'm going toe ad, basically a kind off A list into my existing previously empty Liston. Let's just call it, huh? Just practice. So they're my list has, Bean added. And now the thing would extend is that I've been able to extend my list, but without adding a new list to it. I mean, previously we saw when I added a list to an existing list, I basically the list contained a list built into it. But now, with extent, I've been able to extend my list as a collection off items. I can even go in insert items at a location off my choice because the thing with extend and upend is that whatever is going to be added in it is going to be added. At the end of my less solar insert, something insert. I tone at index to which means going backed inserts. I'm going to use dot insect. Specify the index where I want to add this particular item and let us say I want to add the item. A string item called Molly. Let's just see what happens now. So now we have Gary, Mary and Molly pitches in the third place if I count. But if you remember, this is home. A index moves 012 So when I say index to it is actually from a chronological point, that's the third location. So it is Gary at index zero. Maybe yet index one on Molly yet index. True, because I inserted Molly yet index to by using doctor insect and specifying the index number toe. Remove all this for later use. And now, if I want to delete items from my lists, let's just create another list but numbers and this is the list of numbers. Suppose I want to remove number 14 from my list. I don't want it anymore, so I'm going to call the variable storing my list, which is an US to dot remove, and I'm going to specify the number I want to remove. So 14 has been removed from my list and say Now I want to remove something from Index three . Remember, index number three. Then I'm going toe again. Call the variable. Storing my list, which is numbers to I'm going to use Dell toe delete a certain item from list. And this is the variable storing the list and west to I want to remove the item from Index tree. So I specify the index number in next three. And before I go any further, do you want to take a guess which number is going to be removed now? Okay, just take a guess. Run. Okay. 26 was removed because it was again at Index Tree, which is the fourth place. And there's one more thing we can do. Suppose I want to remove an item from the list and store it for that? I'm going to use something known as pop. So order no stores. The item that I popped from the list and no s to and this was the number at index too. So this was number two. Is that index zero number seven at index one. Number five index trousseau. When I specify index and people, but numbers based on their index. What it does is that it ends up removing five from the list, and it ends up storing it in the variable are and knows a pop is very useful for doing this . And needless to say, we can even print out individual list items by specifying the index. So if I just go back to here, if I want to print out the first item in the list and no s to, then I'm going to specify zero, and it prints out to for me if I want to print out a series off numbers. What I'm going to do is that I'm actually going to specify, say, oneness to fall on. What this will do for me is that it is going toe isolate numbers from index one all the way to index three. So the fourth index won't be included. And as you can see, I have isolated number that index one in next to and in next three from my old list, and essentially we can even modify items in a list. Actually, let me just sprint out this particular list because I made so many changes to it. So this is my brand new list. And if I want to change the item at index one, the second item, then this is what I will do. So there. This is my new list on. Essentially, what happened here is that I have five at index one instead of the previous seven. And this is how we end up replacing an isolating parts off a given list. And these are just some of the very few things that we can do with lists. And we are going to be looking at lists in more detail as the course progresses. But by now, you should be comfortable with all of these operations. And frankly, you should have been performing them as I was performing them on the screen. So once you will complete this, we are ready to move on to the next lecture. 14. Dictionary Operations: in this lecture, I'm going to introduce you to something known as dictionaries and dictionaries are data structure and fightin on a rather important data structure that stores data as key value pairs. You are already looking at a dictionary stored in the variable dicked. And unlike list and two bulls, we declare dictionary is using lead brackets and you can already see that now. Unlike the previous data structures, you can also see that every comma is separating, not one but two values. So what is going on? We have a value. Go alone. Another value. The first value is the key, and the second value is Tokyo is the is the actual value on the actual data that we want to enter because dictionaries they allow us to enter our data or the values on provide labels or keys. So in this case, my key is Japan and the value is Tokyo. My key is China, and the value is Beijing. The key is a and the value of three. We can store more than one data type in a dictionary. Letters run these data and you can see this has been printed out. Let me print out which are the keys, because if you remember, everything is stored as keys or values. The keys associated with my big are Japan, China, South Korea, North Korea A. Now which are my values. You already know which my value, which are the values. But let's just print those out. So values round brackets and the values of the dictionary our Tokyo beating feel Pyongyang three. Now dictionaries are mutable and the enormously important when we want toe store labeled data and we are going to work a fair, better dictionaries for the on in the scores. But in this lecture, we are just going to get a very brief introduction to dictionaries and a general feel of what dictionaries are. So how many key value pairs do I have in my dictionary? I'm going to use the inbuilt fightin function called Len and that will tell you, but that tells us the number off items in the container. And in this case, it is going to be the number off key value pairs in a dictionary and its five, so we don't get an individual number. We just get the number off key value. PEZ, Japan Tokyo is one key value pair China, Beijing, The 2nd 1 and so on. We can even make a shallow copy off our dictionary, using Dr Copy and round brackets, so I've created a new variable. Dicked two is equal to addict, which is the dictionary that I want to copy into addict to dot copy round brackets. So my original dictionary has been copied into addict to now. I want to delete a because it doesn't make any sense here. I'm going to use Dell, then specify the dictionary from where I want to do the deletion and specify the key that I want to delete. Now when I print out Dick to both a and three has been removed, and that is because Dell removes the given key value pair even though we specify a key. So if you want to remove a data item from your dictionary, just pacify the key. Both the key and the value will be removed. Now I want to remove. I want to add a new key key value pair to my dictionary. Onda schema, for doing it is we specify the name of the dictionary. We want to make the additions to square brackets we specify the key name. If it first string, then it's going to be in double courts if it's the number than we won't use number, double courts and the value. So in Dichter, I want toe add HK saw as my key and Hong Kong as the value. Let us just see what happens now. There I get Hong Kong sought while HK saw as my key and Hong Kong as my value. I can even add an integer as my key and a string as my value. I'm going to do that now in this case, then is going to be my key and the value is going to be bullseye. So I have added another key value pair today to after Hong Kong and that is 10 bullseye. If I want to see which value corresponds to a key, I'm going to print it out, called the Dictionary Big two and specify the key whose corresponding value I want printed out. Let's just do that and it tells me the value corresponding toe key or to 10 is bullseye, not to see corresponding to China the value corresponding to the key China. The key China is Beijing I want to see if a given key is present in my dictionary or not. So I'm going to actually make use off in which is a defined word in python. Now if you look at dicked, that solution dictionary that does have a So when I specify a is present in the string or the character is present indicts, it tells me True, because it is present in decked. Now if I want to see B, there's no be over there. Then it returns the falls. I can even say if something is not in a given dictionary, then I use this not in, and this will return true because B is not in dicked and so on. I can even sort out the strings off my dictionary. The key strings using sorted, using the inbuilt biting function sorted. And then we get China, Japan, North Korea. The strings have been sorted alphabetically, and these are just some of the basic things we can do with dictionaries. And in the subsequent lecture, we're going to use mortician Aries, and that is when you're going toe, realize all the things that dictionaries can do for us in the Meanwhile, I'm going to move on to the next lecture and introduce you to functions 15. Define a Basic Function in Python: So in this lecture we're going to discuss functions and to put it simply if we have a court chunk that we have to re you several times, it is a sensible idea to collect all over court together as a function and you have encountered functions before and fightin provides us with a large number off inbuilt functions that we have been using. So let us just go over those first. The most common function that we have been using is the print function, and more print does that. It has been essentially printing out the results off our analyses and programming. And how do you recognize a function? Well, most functions, well, almost all functions. They have a round bracket after them. So when you see the print statement, I have I put after the print statement. We have round brackets and within the round brackets, I have passed an argument which was eventually printed out. So this is what print does, and this is what a function does. Let's have a look here, replaces another function, and we previously used it for replacing one phrase in a string with another phrase, and this was an inbuilt bite and function and again with replace. We had these round brackets and within the round brackets I passed two arguments. It is not compulsory to just pass in one argument and we can have more than one entity passed into a function round brackets all see over here we can even have a function where we don't pass anything. We don't pass any arguments into the function, but we still use the round brackets. So essentially we can has functions in which we don't have arguments. But we will have the round brackets and that indicates that this is a function. And this is an inbuilt bison function. Onda, we can create our own functions and that is exactly what I have done on We can create our own functions by declaring the keyword death. So we put in the keyword death. Then we define the function name see toe. In this case, it is C to F because I want to convert sell shares to foreign height on within the round brackets, I declare I passed an argument Celsius because when we are defining of own function, that usually means that we want to provide an input value to our function with the view off obtaining and output results. In this case, I pass Celsius. The idea is that I won't look inward Celsius to foreign height and I put in the conversion formula for foreign height is equal to nine by five, multiplied by Celsius and sell. See the Celsius is the argument off my function plus 32 then I say return Fahrenheit on the return statement causes the function to exit and hang back of value. And if I want to see the value ice, I said print, which is my function, which is an inbuilt function. I called the function name C to F and within the round brackets I passed the value 10 and that is how I got the 50. Let's just boss another bad deal. They're now instead of 50. We have 48.2 because in my function, see, underscored to underscore f I passed in nine and now we have no that we have created this function. See, underscored to underscore F uh, we can reuse this function as many times we like. Now let us move to the next junk off court, where I have defined a function area under school circle. So I used the key word death area underscore circle within the round brackets I put in radius, go alone. Then I put in by 3.14 and then I returned the value off area for circle based on the radius and just have a look. How is it different from the previous function? The thing is that there's no need to declare an additional variable. And I can just return the computation for area of a circle by our square directly the way you see over here and you can see that I say print. And then I call the function area under school circle. In the output terminal, I get the value 3.14 because in this function area on the school circle, I passed the value one. Let us make it too. And this is we can even input multiple. We can even have multiple import arguments or parameters. So let us look at my function volume. I defined it using death than volume. Within the round bracket, I put in a radius comma height because thes are my input arguments. And essentially, that is how we calculate the volume in this given case and I specify by then I create a variable the in which I put in the formula for the volume off Celinda Radius raise to power , toe into height by our square age Basically And then I return it because essentially I want the value to be returned. And then I print out my result the way you see it. And then my output console tells me that volume of cylinder with radius one and high to a 6.2. So essentially, these are some of the very basic functions that we have covered in this lecture. But now you know that what the syntax off a function looks like and the fact that we can pass passing more than one argument to obtain a desired set of results. And we are going toe revisit creating user functions at different junctures in this course . So make sure that you understand ho the flow and sing backs off functions works, so you know you don't have a problem 16. Create a More Advanced Function: Okay, Now we're going to carry on on and just cover a little bit of more ground on functions. And I have two functions, essentially a function to convert sell shares to Fahrenheit and Fahrenheit or Celsius. It is the same function. I think I created a function by the name C to f using the keyword death I pass in cell Shias because it s Celsius that I'm going to use toe, compute the value of Fahrenheit. And then I returned the Fahrenheit. But what happens if I want the user toe input the value? And we've already seen that that we can get input from users and that is exactly what I've done here. So if you if we look at line nine off this file, we can see that I'm using Celsius, which is the argument off my function. And I want the user toe input, the temperature and sell shares, which I'm going to convert toe end using the inbuilt fightin end. Because if you remember, every time we get an input from the user tighter than string. And then when I print the output in my seat with the argument I'm going to pass, is sell shares and the user input will be used to compute the value of Fahrenheit. So and before I run that function, I'm going toe. Look at this function as well. Fahrenheit to sell shares and the function name is F to see. And I'm going to import the value of Fahrenheit because it is sell shares that I want to compute using Fahrenheit and that Ive declared US capital F and sell shoes X equal toe F minus 32 so on. And I'm going toe except the input value off Fahrenheit from the user. And then I'm going to pass it into the function f to see and brackets. If because I'm going to call the function, remember, when we create the function, we also have to call it. But there's a small difference here. Let's just see. In one case, I'm returning the value off the essentially as a way of accepting and handing back of value . So that is why I use return Fahrenheit. But in the second function, instead of returning the value of sell shares, and that is what the function is computing. So instead of returning that put, I'm simply printing it So what happens? Actually, let's just run this fight and code and then we will tackle that issue. Enter temper temperature in Celsius. Spend on the Fahrenheit values 50 and the temperature in Fahrenheit 50 on the social value will spend. So, practically speaking, there's no difference between using the return on the print because at the end of it I get the same output. But here is the thing. And let us just run these two dummy kind of functions. And in one case function F one is going to print at five, and F two is going to return seven. And then what happens when I call X and Y? Basically, when I pass function F one into X and function, why into f into why? And then print them out? They're when I print exe and remember, this comes from function F one, where I printed out the value. What I get is none because F one does not return a value. But when I print out why, which was stored in F two, I get eight and this is because with print, we just display the standard output off the value on with return, we essentially send the foreign height back to the color, and when a return statement is used, the function off that output can be used again. So that is just a very small in a subtle difference between return and print. So if you want to I use or reuse the outputs off your functions, then you should be using the return statement. 17. Rationale Behind Looping: the rational for this section is very simple. I'm going to teach you how to build a very simple number Guessing game in Piketon and the up short is that I will try to get a number from 1 to 20 on the game will tell me if the number I have guessed matches a number, guessed by goodbye. Abide it, The Beytin interpreter. So let us just play this game to begin with. My game has started and it's asked me to get a number. Let's get the number. What's your guess? Too high? 19. Too high. Let's try eight. So as you can see, I'm playing a game and I'm being told, you know, whether I mean given hands, basically, you know whether I'm close to guessing the correct number or not. Now, by doing this, I know my number is somewhere between 8 to 20 or it to 18. Too low, too low to know too low, too high 17 is too high. So let's just try 16 exit. So I managed to guess the correct number, which is 16 and now I exit. No, this is a very simple game, but and before you can build a game like this, you have to be introduced to something known as loops. On loops are a kind of programming logic, and basically they allow us to provide a sequence off instructions that is repeated until a certain condition is reached. So as you can see, loop involves testing and expression or expressions, and as soon as the condition is met, the Lupus executed. Otherwise, things are not going to be executed, so we have the loop condition, expression. If it's false, then you know the story ends and we move to the next thing. But if it is true, then whatever we want executed will be executed on. In order to build a game like this, you have to be acquainted with the major kind off programming loops that there are in fightin and the same looks they exist for other programming languages. It includes things like, if else so you know when you want to test. If the number you have guessed on the number that the Beytin interpreter has produced, you know, other the same or not that needs us to use something known as if Ehlz. In addition to NFL's, which is one of the simplest forms of programming loops. We have things like while you know, a look that will run while a certain condition is being met or is not being met. So in addition to these three main loops, we can combine them together to build very simple games like the one we did. So in case you're new to programming loops, the next couple of sections are actually going toe talk you through programming loops, the different kinds of programming loops you threw, very simple exercises, and then finally, we will going to build the game that I just demonstrated right now. 18. If-Else Loop: in this lecture, I'm going to talk you through testing conditions, using something known as the NFL's statements. And I'm just going toe introduce very simple examples pertaining to the same. And before I do that, I'm going to reiterate the bit about conditional operators that I had touched upon very briefly previously. And essentially, what you see under the operator column are conditional operators. Things like double equal to signs the test. If, say, two numbers are equal or not, the greater than sign it tests, whether a number or an entity, a variable a is greater than very will be or not. And if it is, then it is true. Otherwise, it is false and sworn, and these are some of the most common conditional operators out then any programming language so you can see them and we're going to start working with them. So don't worry. And you don't have to worry about writing these down and things because it's fairly straightforward, and by the time you finish the schools, we would have worked with them plenty, and you should be comfortable with them. But first, let us just see how these conditional operators work before looking at what if else statements do so when I print eight to equal to science nine, my output is falls, and that is because eight is not equal to nine. But let me replace this nine within eight. Now, my output is true because eight is indeed equal to eight. And now let me see if eight is greater than eight. This is false because eight is not greater than eight. But this particular symbol stands for greater than or equal to like. So this is true, because while it is not greater than it, it is certainly equal toe eight. And that's why we get the output true. And essentially, these are some of the things that we test using. If else functions. They fell statements. And now let us actually create a very simple and ah, very small if else program and the key thing to remember about it. Fells testing is that you have toe account for things like in dense, and most of the fightin interpreters are ideas. They do it for us. So this is my program. I have put in a variable X, and my X is equal toe eight. So I have assigned the value off eight to the variable X by using a single equal to sign. Because if I used to equal to signs, that means I'm checking for equality. Now I declare if and that has been collected purple if X is less than or equal to six. If it is, then we print small. Otherwise, else we print big. And that is what if else do so in the case off, If we're just testing, say, a binary condition, you know, is X greater than all is X less than or equal to six. Then in the if is going toe test the binary condition and else accounts for you know everything else. That's just so first, The Beytin interpreted moves to this part of the code. It checks if X is less than or equal to eight. Since it is not, it cannot print small. So then this falls fairly and squarely under the category, or else because anything else besides this, If condition is an else and we print big, that's just now let us see if X is greater than six. Great greater than equal to six or not since Xs eight, and we want to see with greater than or equal to six. This condition is true. So if the condition is true, then the program will terminate here. And that is why it prints out small because it prints. Then it executes whatever is written over here within the print statement. And we don't even have to give a print statement after the If what happens is when we declare the If we are trying toe test for a condition based on the conditional operators we saw. And if that condition has bean met, then whatever we have in this junk off court, for instance, we just have one line which is print small, that gets executed, and obviously the condition is false. Then we would move to the else part of the code, and whatever is within the else junk off code would get printed. And this is the logic behind the FL statements and weekend best. Anything we like with it. Let's Chrissy cool now it prints big because the condition off if has not bean met X is not greater than four is not greater than or equal to six. So this condition has not bean met, so this junk will be ignored or whatever is present in this bit after the Earth will be ignored and we will move straight toe else on. Remember, these indents are very important. So when we have, if declare, you know with after, if we declare the condition we want to test Golan's and then we need an indent to write our program, you know whether it's one line or we write more than one line. We need an indent and same with else. And this is the simplest execution off if else. And now we are going to see what happens when we want to examine more conditions using these if else statements. 19. Elif Loop: now in the previous lecture we worked. But if else and we basically used if toe test one given condition and if that was meant if that was met, we printed out to give an answer on. If that was not many met, then obviously then our code moved to else and the answer in that block was printed out. Now we're going toe expand the scope off. If Els on look at something owners LF and what LF does, is it lets us best more than one condition which, if else doesn't so I have imported random. I've created five variables on the one to treat all the way to five and that stores the names of different pet animals Cat dog all the way to a kitten on. Essentially, I want to select a bet you know, which is the most suitable pet for keeping in a flat and invariable choice. I have put in random dot rand end, which is going toe randomly select any number any integer from 1 to 5 and you already acquainted with ran with the random package. And what we are going to do is that now we are going to look at what if, if else and LF do for us. So if my choice is equal to one So which is that If the number selected by random package random is one, then my answer is going to be answer one. So basically it's going to be a cat. But since I have more than one very ableto test, then LF lets me put in choice is equal to do and my answer is going to be Answer two and let me just carry on all the way to my l statement This junk off and lift code This will run if my if the choice it comes up to be three. So if the random package produces the number three in its iteration, then my code it will move. You know it will test whether it is my very able is one or not. Then moved to this. LF this chunk off gold and then moved toe this LF this particular chunk off code and then print out this particular answer or rather execute all the court which present under this a left a left chunk. So essentially, this is what life is doing. It is going to help us test multiple conditions. And if you are typing along, remember the indentation. So it's going to be like this if a live and indentation indentation is very important for fightin. Otherwise we get an error. Okay, Suppose the random number that the random package chooses for us is not 123 or fourth, you know, it will be five. Obviously. Then my code is going to obviously look at all of these, but eventually, then it will execute all the code snippets present under the else junk. So if I want to print out my output, which I do, then I'll have to go out of my indented the way you saw me do it. And before I run it. This is what your program should look like, complete with the indented. So if Joyce is equal to one than this part of the code will be run and live. Then I'm going to test with l. If I'm going to test if the variable choices to If yes, then this code will run now with another live, I'll test. If the very able produced is three. If yes, then this gold will be run. If not, I will come through the bite and program will come to this bit. If my choice comes up to before in this part of the code will run. And it is LF which is directing the show, if it's not 1 to 4, then I'll move into the Els territory because, you know, we have exhausted all the possibilities. And when all the possible outcomes are exhausted, then you know what? What what is left is what else executes for us. No, let's just see. So know my number has come upto go to the choice that has been selected for me has come to goat. So I assume that my choice variable that, um, mother, the random package that threw up three. And that is why we came to this particular a left bloc. Enter five. So what happens is that when my cold ran, the first thing it did was to print this, select my pet. And then it saw it asked me the question which is the most suitable pet for keeping in a flat. And when I pressed enter it moved to this line of the court. Choice is equal to random doctor and end on the random package. It threw off a number, and in this case the number was five. And as soon as the variable five was recorded in choice, the program move further. So if I was equal to 1234 no, obviously not, then it's so when it saw that you know, none of these conditions are being met. Then, in the Sherlock Holmes style, what was left was this, and this bit was executed. Ants five. And basically that's why we get a kitten and I think it and are suitable for keeping in a flat. Enter Oh, another kitten. It's a season for kitten respect. Oh, do dog. It's what it did was basically when I press the enter key, it came to this line of the court choice and you know, random. It works like shaking her die. So when it produces, too, who is not equal to one. So from if it moved to this left chunk since two, it is equal to two. This part of the court unsaved equal toe ants to was executed and when it was executed. This is the outcome we get So essentially, this is how if and if else work and this is how LF it allows us to test multiple conditions 20. While Loop: in this lecture, I'm going to introduce you to something known as the while loop on why loops allow us to execute the court. While a condition is true on like before, we specify an initial value on the loop run. Still, the wild condition is true. So basically, while the wild condition is true, the code is executed. And now I'm going to show how we can use the wild loops to, say, print out numbers from 1 to 10. - So I have initialized a variable number and I've assigned it the value one. And now I have declared my wild condition. And that is while which is blue, which is what I want to execute. So while my number is less than equal to 10 I'm going to print out the number on essentially, this condition is going to be executed till the number is less than or equal to 10. It's and number is equal to number, plus one is going to start incriminating our numbers. So we're going to start with one and increment the numbers one by one till we reach then. And after that the condition will no longer be true. And the coat the loop will terminate. They're the numbers have been printed out all the way till 10 and say this happens because I've used less than equal to. If I just use them, use the less than symbol. Then I would have to specify number less than 11 because it's going toe essentially print the number less than 11. Let us just see how so Now my condition is that the number is less than 11 on by. And while this number is going to be less than 11 which is still 10 the numbers are going to be printed out. And I have already declared that the number should be incremental one by one till we reach less than 11. And now let us just execute this there we get the same out, Bert. But if this was then that, then we would get a nine. And that is because nine is less than 10 and that this chunk, the score chunk, is only executed while the condition is true. So the number is less than 10 and essentially, this is what the while loop does for us. 21. For Loop: in this lecture, I'm going to introduce you to some very simple implementations off the four loop on four Loop is something that we use for ICT aerating over items and you can see well in the previous lecture, we had used a while loop to print out numbers, say, from 1 to 10 or 1 to 11. Now I'm trying to do something ready similar over here, I've declared my foot. I've used the keyboard four, which says, which essentially tells my Python interpreter that I want to start a four loop for I in range. Then now I is an iterative er, and it is I that is going toe iterate on by range. 10. Ranged is an inbuilt bite and functionality, which prince out numbers in a given range. So when I say range trend, essentially it'll print out numbers from 1 to 10. And now let us just do this So numbers from numbers up to nine have been printed out. But because when I specify range, 10 essentially just prints outnumber still nine, and we saw that in the previous lecture when we were working with the while loop and I can even the thing with range is that if I want to point out the first time numbers and I specify 10. But if I want to friends numbers say, from between 3 to 8, then the first number I will give it is three, and the second number will be eight and let you see how save they're. So now I will iterate over numbers 3456 And since I've specified 77 is going to be left out . So it will. I trait over numbers in the given range 3456 and those will be printed out using the print function. Now, if I don't want to print out consecutive numbers, I can even specify steps. So the starting number, the ending number and the steps So instead of connective numbers, what has been printed out as 357 So I it I traded over 3 to 9 using steps off, too. So instead off I treating consecutively, which is the default behavior, my eye to ream the four loop iterated my eye over this given ranges numbers in a step off, too, and that was printed out 357 And since with range we do not print out the last number. We stop at seven because we're using a step off to now. As you have observed before overnight. The code, I commented out. We can even use a four loop toe. I trait over a list of items, so let us just do that. So what happens is that I have declared a list containing the names of different fruits apple, pear, grapes, melon, orange. I start my for loop, using the keyboard for my eye. Traitor is if it will iterate over the list called fruit. And when I say print F, it ends up printing out the names off all the items in the list fruit, which is the names of the fruits. And essentially, this is how we use I trade four toe I trait over, ah, collection off items and in certain cases for look and even substitute the while loop and what we have done so far, it's a very simple implementation off these different programming logics and loops, and in the next lectures and sections, we are actually going toe build upon this basic knowledge toe, execute more detailed and complex tasks, so just make sure that you understand this potion 22. More on Looping: okay, we are going to carry on working with other loops and basically some more programming logic . And one of the most important things that loops especially four loop can do for us is that it can iterate over data structures. So now I'm going to create a four loop toe I trait over a dictionary. Dictionary creation is something that we covered in the previous section, - and as you recall, the first and for you over here is the key and after the semi colon is the value. - So my dictionary has been created. Now I wish to use a for loop toe I trait over this dictionary and let us see what happens when I use a basic for loop toe iterate over this particular dictionary. So what it has done is that it has printed out Japan China, five on South Korea. And if you look at the dictionary, you can see that these entries correspond to the keys. So when we iterate over, additionally by default, what is printed out are the keys. Now we don't have that problem with lists because lists the Justo items additives and the entire list will be printed out. But in this case, we have ah bit of an issue that it is the key that is going to be printed out now. What happens if I want to print out the values as well? - Four loop hazard. One page off using to fight aerators toe iterate over two different entities in a data structure. Therefore, I specified to I traitors K doctor, we instead of just an ordinary I and let us see what happens then. Now the first iterate er is going toe iterate over the first and two D, which is the key on the second iteration V is going toe iterate over the second entity value and we will just see how that pans out in a minute. - So now we get Japanese Capital city. Tokyo Capital city was a string that I put in. But the important thing to realize is that gay iterate id over the keys, the iterate Okay, I traded over the keys on iterative v ICT aerated over the values. So but loops. We have the option off having more than one item. Reiter, help us explore our given data structure like a dictionary in more detail and items is an inbuilt whites and function, and it is basically an object that provides a view on the items stored in the given data structure. In this case, it was the dictionary. We may also allude to the index and now my idea Reiter, I it iterate ID or worth the keys which are Japanese China, five on South Korea. But when I allude to addict I, it goes to that particular index in the dictionary and outputs the corresponding value toe that given tea. And that is how I get Tokyo Beijing the pie seal. And in addition to iterate ing over data structures, we can combine programming loops toe, actually help us perform simple al automatic activities on a given data structure, and I will show you how now printing out a given range of numbers is something we have encountered before, and we have used four loops for doing the same. But then why would I want to print out numbers from 1 to 20? It would be more useful if I could perform some kind of a mathematical operation and, for instance, say I want to print out all the even numbers from 1 to 20 or 1 to 2000. Now this is where programming loops and combining programming loops really comes in very handy. And now I'm going toe ad. And if statement inside my for loop to carry out this activity, this particular line, it just specifies if a number is divisible by, do or not. And if model list two is equal to zero. So when we divide the number by two and we don't get a remainder when that number is even and I want to print all of those numbers out. And now if you see the outpour 12 14 16 18 20 These are all even numbers and they have bean printed out. And essentially, this is what combining different loops scanned do for us. Basically, we can perform specific computation activities on a given data structure, and what you saw over here is a nested loop off sorts, and we can even nest to four loops together to carry out computational activities. Let us see how 23. Nested For Loop: Finally, after working our way through so many different kinds of loops and their combinations, we come to nested for loops. These are complicated, and therefore, let me just take you straight onto an example. See, over here we see something like Cat Dog printed three times over, followed by cat Dog, printed three times over and so on. And this loop has been repeated repeatedly, and this is what nested for loops do for us. Over here. I have created nested for loops outer loop in a loop, and we can say we can see that I've already declared for X in range 1 to 5 print cats. So you know, I want to print Cat four times, but then I just don't end up printing cat four times. What happens is for why in range 1 to 4 print dog, which means I want to print my dog three times and then I finally print over. So then what happens here? Andi, I think seeing that my choice off range, you can see that somehow my dog was nested into my cat. So now let's see how that happens. What nested for loops do is that they will run the outer loop once and print cat, and that's how you see cat. Then, instead of going on printing cat, the program will move and it will run the inner loop, according to the range specified. And in this case, it will print Dog three times because I specify range, witness to four, and you know that will only go up to three. So it'll print dog three times, and it's done that. Then the final line off the loop will be run, and that is over. And that is how over gets printed out over. Then what happens? Then the program goes back to the start of the outer loop on the previous steps are run, and that's how we get our cat dog three times over and the loop is run four times because in the outer loop I specified my rage to be 1 to 5. So that means it'll run four times. And essentially, this is how nested for loops work. And now people start putting this all of this knowledge together to build a very simple number guessing game 24. Number Guessing Game-Basic: in this lecture, I'm going to start building a very simple number guessing game. But before we start the actual coding, I think we should have some idea about the different program. It take steps that we will take to build our program, and that is known as designing an algorithm. Obviously, algorithm design is a highly complicated process, so we're going to really focus on designing a very simple algorithm, and it is not exactly formalized algorithm development, but we will develop a simple algorithm and try to execute the same in beytin. So what do I need for my number guessing game? I need the computer to generate numbers in a given range. Then I want to be in a position to input my guess. We've already covered how to generate random numbers within a given range, and we also know how to import how to get imports from the user and to convert them to images. So that is something you are already familiar with. But once we do that, we need we need a way to compare if these are equal or not. And if you remember for comparing for comparing numbers, we have the If else programming flow so we can check if our numbers if the computer generated random numbers and if our guests is true or not using a fells Andi for the sake of convenience, we are going toe put all of these in a function to run. So now let's go ahead and start programming. I've already imported random, and I've created a variable computer number and that is going toe basically take the random numbers generated by the computer. So so random. The variable computer underscore and no, is this particular entity Basically Now I've created a function using death. The function is called same number and I have a target and a number. These are the arguments if the target is equal to number than my result is when else it is false and the function returns the result. And I'm going to take guests from my users by using input and it'll be raw, important case off by 32 it will be converted toe end. And that is my guess and basically computer and no, and guess they correspond to the arguments because essentially, what the arguments after I will do is to compare the computer number and the guests with each other and see where they took bin or a fail. And once I get the guests from my user, I've printed the function same number same and no. And I have a friend in our own arguments because these are the arguments that I want to test, which is computer number, the computer generated number and guests. Well, you know already, guess is this particular entity. So now let's just run this game since my computer generated number is going to be in a very short in a very small range from 1 to 4. I should also guess my number accordingly. So let us guess. Three win, Which means that my computer generated number was also three, and I also guessed three. So this is the simplest version off the number guessing game. But what happens if I generate numbers between 1 to 50? Then my game becomes very car complicated because then I have literally 50 numbers to choose from, and I'll put you know, and it could be just any off those 50 numbers. And if I'm unable to guest and I'll just be it won't be a game. I'll just be stuck in some kind off loop in a vicious circle. So maybe if I want my game to become more interesting, I should be able to guess 50 numbers on my program should also give me hints. You know, if I if if my guess is too high or too low. So now we're going to carry on and see if we can make the game slightly more complicated and slightly more interesting and intuitive. 25. Number Guessing Game-Intermediate: Now we are going to continue and build on the game that we had been working on previously, and we are going to make things more challenging now. I want to be able to play with more numbers. Basically, I warned my range of numbers to be 1 to 20 and I want to be able to guess the correct number from between 1 to 20 on that will require me toe extend the previous program that we had created. So the first thing is that we are going toe again, have a computer generated number within a given range. Then we are going to take the users. Guess, check if the numbers are equal and if it is, then it is a brain and we've gone that far. But since we play with 20 numbers, you know it can become a bit of a thankless task. So what happens? Maybe it might be more useful that we tell the player that if the computer generated number is greater than the number we have guessed, we provide them with a hint that it is low on. If the computer generated number is less than what I have guessed or the user input. Then we provide them with the hint that actually, it is just too high. So, you know, they may just have a better idea. Which number two guess So now let's just carry on and build this So it's the same thing. Import random computer underscore number. This is going to stall the random numbers generated using random dot redundant. And now we're going toe. Generate random numbers from 1 to 20 on my guests. The variable guests is continued will continue to store the user input. But let us just go and change this particular function. Same number and obviously target and number. They are the arguments that we have bused into our function because, you know, this is how we test if the if the target and away on the number we have input, you know, other meeting the condition or not. And if yes, then we when If not, we fail. So now let's just extend this. If the target, which is a computer generated number, is the same as number, the number that we have guessed, the result is when this is a no brainer, that should make complete sense to anyone. But I'm interested in something else. What happens if the computer generated number is greater than the number that I have guessed? Let's just write it down some polluter number greater than my guess. Let's just provide people with a hint that it's too low, and basically they'll have to adjust their estimates accordingly. Otherwise, when it's the other way around, you know that my guess is greater than the computer generated number than we just tell the user that their guess is just too high and we'd return the result. And obviously we print. This is how we start the game. Let's gets a number. And now this is where we take the user input. I've created another variable, high underscore law and this and in this I have passed this particular function same number . And this is where we're going to feed in the computer number and guests. And obviously, instead of printing the result now, I want to store the result in this particular variable high underscore or underscore low and then carry on working with it. So and this variable is going to stop whether I have one or I've lost or sworn So while I'm not, I'm yet to win. - So this is a wide loop and this is going to run Bill. The condition is not met. So, you know, till the point we don't win, the program will carry on. And now I'm going through use a combination off loops. And now I'm going to use violence if loops together. And if you recall in this section we had combined our looks together. So you know now let's just start testing the conditions the way we did before with a fells . - So now with that, if else loop, I'm going to test, you know, if the variable stored in my high or low If the outcome off my higher low is low than I just tell the user that their guess is too low, they need to try again. And with else obviously it's the other way around. So and again, we call the same function. And we guess you know, if I will compute if the computer generated number is the same as our guests or not Tullow , try again. So what happens is that essentially this part off my gold was executed. Silly me Do high. So obviously my number was too high So I've been told that I should try again. And because this is how we import data and from from the users and therefore I'm being given this option toe essentially try again. So now I can guess that my number must be somewhere between 11 and 18. 11 and 17 selections go to 17. Too high. Try again. Were to go down 16 too high. Try again. And it is this part of the court that is being executed. 15. Do I try again? Exit. That means the number. That computer guest was 13 and now I can exit because as soon of that put an exit. It took me out of the loop and brought me to this one. And the one assume that I pressed. Enter the game terminates. So essentially, this is a very simple number guessing game. But as you can see, we ended up creating an entire we ended up modifying a given function and, you know, and then using outputs of that function higher low toe, create this particular programming logic chain while you know, while we don't win the NFL sloops, they carry on telling us to go on guessing. And you know. Based on the hints they provide, you managed to narrow down the range of your number than eventually I guessed 13. So with this, you've created your first simple Bytom fightin based number guessing game. And congratulations if you've gotten this far because this is this right, this program frankly involves a lot off programming logic and getting a hang off loops. And in case things are not clear, I would suggest that you go back to working through all what we have covered about loops. 26. Number Guessing Game-Advanced: So far, we have built a number guessing game, and this is just an optional addition to the game that we have built so far. On the up short is that we'll make it slightly more advanced and slightly more competitive that essentially now the users, they will just have five guesses to guess the number. And if they can't guess, then they lose and we tell them what the computer generated number. Wars. Andi. If they I guess the number correctly in the first instance, they get a school or five, and if it takes them time than obviously, we deduct the number off. Guess is taken from the school, which is five. So I'm going to carry on building the game, and I've imported random print. Let's gets a number computer underscore night number, random dot rand end, and this is going to store the computer generated random numbers. Now I'm going to initialize to more variables. Guesses taken is equal to zero, and score is equal to five because so far when we start the game, we have not taken any guesses and the score is five. Now I'm going toe in case my entire code in a while loop and wild guesses taken are less than five. Then I'm going toe. Take the user input. Yes, input. What is your guests? And then, as soon as a guess is given, guesses taken will be plus one. So you know what every guest that I take, plus one is added on. If my guess is equal to computer number, then my score will be five minus guesses taken. And essentially I win with a score off. Whatever I get five minus guesses, taken else. If if my guess is greater than the computer number, then the guess is too high. Els. The guess is too low on if the guests is equal to computer number than I'm done. And you know, if I'm unable to guess the computer generated number, then I lose and the computer guest number will be printed out for me. No, let's just play this game. And this is just a brief modification, so we won't be using the user defined function anymore. On the upshot is that I've only added a while loop to my game, and I added some cold toe taking the score because that's going to be five miners guesses taken, and that's that. But it's just that it makes the game slightly more interesting. So now let us run the bite and file. What is your guests? 16. It's too high. Let's make it 12 too high. Let's make it eight. So I've been with a school off, too. And I got a school off, too, because it took me three guesses and five minus three is two. And you know, if I if you can't guess and we come over here and essentially the computer generated number will be printed out for us, Let's just try this again, you know? Okay, So I went with a score off three because I guessed it over two guesses. So you know, this was number 10 was my second guess, and five miners to is three. And essentially, this is how we play the game and just modified by adding one overall while loop to just restrict number of guesses, we can take 27. Conclusion: So we come to the end of this section three and we have covered a lot of ground in this section and you have bean introduced to programming loops and what we can do with these programming loops. This these are very important concepts to master both for beytin programming and for programming. Enjoy. General, you have been provided with an introduction toe fl sloops and you know how you contest a binary condition with an if else loop. You noticed If a number is greater than a certain quantity or not, use off LF to expand the scope off. If else condition testing has been covered, we have also covered the use off while loops and these are the loops that are executed by the condition is true. You have been introduced to four loops. Now you know how you can use loops for I trading over data structures, you also being introduced to combining loops and nested loops. Finally, we applied all this knowledge together with our previous knowledge off defining of our own functions to build a very simple number guessing games. And then we finally added at once creatures to our game using loops and in case you are brand new to programming some of these things. They may seem a bit complicated to begin with, so I would urge you to go over the individual lectures again if things are not clear, and obviously you can or always message we directly or contact me through the discussion boat. But now we are ready to move on to the world off grease and graphics after you answer a brief quiz.