Python 3 Fundamentals: Beginners Guide to Python Programming | Michael Murr | Skillshare

Playback Speed


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

Python 3 Fundamentals: Beginners Guide to Python Programming

teacher avatar Michael Murr, Software Engineer :: Game Developer

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

50 Lessons (4h 57m)
    • 1. Why You Should Watch This Course

      3:10
    • 2. Section 1 - Introduction & Setup Python for Windows/Mac

      2:47
    • 3. Downloading IntelliJ IDEA for Windows/Mac/Linux

      4:23
    • 4. Setting up IntelliJ IDEA

      2:39
    • 5. Section 2 - Getting Started In Python: Our First Python Program

      6:15
    • 6. Printing in Python

      6:26
    • 7. Strings in Python

      9:12
    • 8. Special Characters

      7:31
    • 9. Variables and Types

      8:22
    • 10. Something To Watch Out For

      4:06
    • 11. Numbers Operators

      7:42
    • 12. Operator Precedence

      3:09
    • 13. String Data Type

      6:12
    • 14. Negative Indexing in Strings

      3:20
    • 15. Slicing Strings

      6:30
    • 16. Slicing with Negatives

      3:56
    • 17. Using a Step while Slicing

      5:36
    • 18. Slicing Backwards

      5:46
    • 19. String Operators

      8:55
    • 20. Printing numbers

      10:28
    • 21. Section 3 - First Steps In Python: Introduction to Blocks and statements

      7:03
    • 22. If Statements

      8:59
    • 23. Elif Statements

      5:23
    • 24. Using the Debugger in IntelliJ

      5:34
    • 25. Deeper Into Conditional Statements

      4:12
    • 26. Debugging if, elif and else

      3:08
    • 27. Adding a Second Guess

      5:38
    • 28. Testing Operators

      8:01
    • 29. If In A Different Way

      2:18
    • 30. Complex Expressions using and, or

      5:32
    • 31. Simplify Chained Comparison

      6:31
    • 32. Boolean Values (True and False)

      8:17
    • 33. Truth Value Testing

      6:35
    • 34. Section 4 - Loops In Python: Introduction To for loops

      6:13
    • 35. Debugging a for loop

      7:52
    • 36. For loops over a Range

      2:24
    • 37. Deeper into Ranges

      4:10
    • 38. Nested for loops

      7:18
    • 39. Using continue in for loops

      8:01
    • 40. Using break in for loops

      8:17
    • 41. Why Use None

      4:13
    • 42. Section 4 - Loops In Python: Introduction To while loops

      6:42
    • 43. Deeper into while loops

      6:18
    • 44. Break in a while loop

      3:12
    • 45. Random Number Generator and Importing

      9:29
    • 46. Binary Search Algorithm 00

      4:31
    • 47. High Low

      8:16
    • 48. Completing our Game

      6:08
    • 49. Else Statements in Loops

      4:45
    • 50. Else in High-Low

      5:36
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

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.

56

Students

--

Projects

About This Class

This course is aimed at complete beginners who have never programmed before, as well as existing programmers who want to increase their career options by learning Python

Python is one of the most popular programming languages in the world. Tons of Huge companies like Google use it in mission critical applications like Google Search. It's the number one language choice for machine learning, data science and artificial intelligence.

Python is an incredibly efficient language: your programs will do more in fewer lines of code than many other languages would require. It's design philosophy emphasizes code readability. Your code will be easy to read, easy to debug, and easy to extend and build upon compared to other languages.

To get those high paying jobs you need an expert knowledge of Python, and that’s what you will get from this course. By the end of the course you’ll have a solid foundation in Python programming. And yes, this applies even if you have never programmed before. With the right skills which you will learn in this course, you can become employable and valuable in the eyes of future employers.

Section 1 - Introduction & Setup:

In the first section we're going to download Python on our computer (Windows, MAC) and set it up. We'll then download IntelliJ IDEA a very versatile IDE to use for multiple languages and especially Python. We'll also set up Python SDK so we can create and run Python code.

Section 2 - Getting Started In Python:

We'll create our first Python program. We'll learn about printing in python and learn what strings are and how we can slice them in order to extract certain data from them. We'll also understand how strings are a sequence of characters and that we can actually index through those characters, so this will be a small introduction into Lists.

Section 3 - First Steps In Python:

In this section we're going to learn about code blocks and how we can use conditional statements to execute certain code only in certain conditions. We'll learn how we can use the Debugger in IntelliJ and understand how important it is. We'll also delve into testing operators, Boolean values and Truth Tables. Finally we'll see what complex expressions are and how we can use them to our advantage to make code more readable.

Section 4 - Loops In Python:

This will probably be the most fun section. We'll delve into Loops, for loops and while loops and learn the difference between them and when to use each. We'll learn different tricks to use in loops such as break and continue and apply those tricks to create fun games. We'll also learn Binary Search Algorithm that will introduce a bit of intelligence to our program.

What You Will Learn In This Course:

  1. Download and install Python

  2. Download and set up IntelliJ IDEA as your IDE

  3. Set up Python SDK

  4. Learn how print works in Python

  5. Learn how stings work in Python

  6. Understand what special characters are in Python

  7. Understand how to index through strings

  8. Learn how to slice strings to extract data

  9. How to using string operators

  10. Create conditional statements

  11. Become an expert in complex expressions

  12. Learn about Boolean values

  13. Understand what Truth tables are

  14. Learn for loops loops

  15. Learn While Loops

  16. Delve deeper into loops and use them in new games

Meet Your Teacher

Teacher Profile Image

Michael Murr

Software Engineer :: Game Developer

Teacher

Hi there, my name is Michael Murr. I'm a software engineer from one the most highly esteemed universities in the middle east. 

I started coding when I was about 11 years old when my dad taught me my first lines in HTML and I have never looked back.

Now a Software Engineer with more than 10 years of experience.

Over the years I've helped thousands of student create games, learn how to code and set their life up for opportunities in many fields that require a software programming skillset. And I will help you do the same.

I have a complete mastery of Python, C#, JAVA, C++ and my aim is to teach you all of these and more in a fun way.

I cannot wait to help you start on your journey and help you along every step.

I'll see you very soon!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. Why You Should Watch This Course: Every programmer has a story about how they learned to write the first program. An experience that has a lasting impact. There is real satisfaction and building something with a purpose, something that solves a problem. No doubt the best programming language to learn is, by far. My name is Michael Moore, founder of WMD. I've helped thousands of aspiring programmers create real-world programs and I want to do the same for you. Why? Python? Python is an incredibly efficient language. Your programs will do more and fewer lines of code than many other languages would require. It's designed philosophy emphasises called readability of your code will be easy to read, easy to debug, and easy to extend and build upon compared to other languages, python has many purposes to make games, build web applications, solve business problems, and develop an internal tools at all kinds of interesting companies. This Python course is written for people of any age who have never programmed in Python before or have never programmed at all. My goal in this course is to teach you Python as quickly as possible. So you can start building programs that work like games, data visualization, and web applications. So if you want to learn the basics of programming quickly, and you'd like to test your understanding of new concepts by solving meaningful problems. This course is for you. So how are we going to do this? In the introduction will download Python and set up the environment on our Windows and Mac to start programming easily. Then we'll start learning basic programming concepts you need to know to write Python programs. You learn to create conditional statements and how to use while and for loops to test for certain conditions. A technique that greatly helps to automate processes. To learn to accept input from users, to make your program interactive, and to keep your program's running as long as the user is active, what should you expect by the end of the scores? You'll become a master problem-solver. You'll understand the fundamentals of Python programming and learn to read and write Python code easily. You'll also have the chance to flex your Python developers muscles. Because with every video there is a challenge for you to complete. And even if you can't figure out how to do the challenge, Don't worry about it. I will be there to help you after you've tried. I'm so excited to get started and hope you are too. This is the perfect time to start learning how to code. So dive in with me and I will help you along every single step of your Python programming, the journey. 2. Section 1 - Introduction & Setup Python for Windows/Mac: Oh, okay, so first off, what is Python? So, Python, this is the symbol for Python. Python is a high level and general purpose programming language. Python is designed to emphasize code readability and it uses and limitations instead of brackets, if you're familiar with different languages such as C or C plus plus or C Sharp, you know that usually do those codes and other codes such as Java also use brackets. While Python, because it emphasizes code readability, we use indentations instead, and we'll see what that means later on as we progress through the course. Now, the first thing we need to do is we actually need to download and setup the environment of Python on our PC. So an order to do that. First of all, we'll open up Google Chrome and we'll go to Google and write and download Python. Now you should see many results in here. So go to the link where you have the WW dot python.org. Click on that. You should be prompted to this page right here. You should have, if you're on a Windows, download the latest version for Windows, it should be in here. If you don't, you can go to the downloads right here and go to the Windows, find it if you're on a Mac, you can also go to the Mac OS. And before you continue on, if you go to the page right here, for example, you need to make sure that you are using the latest version. Maybe you have a newer version than this. Make sure it's Python 3 and it's the latest one. Now, one more thing that you need to make sure of is that you need to know if you have a 64-bit or a 32-bit Windows. And then when you download the installer, you should get this icon right here. Maybe it's different, maybe it's not simply double-click, double-click, run and start installing Python. Now, I already have Python on my computer, so I don't need to install it again. And as you install it, it's a very easy process. There is nothing too complicated about it. So one more thing that you need to make sure of is well, installing. You may get asked to add a Python 3.9 to path and you need to check that and continue on installing on Mac. I don't think it will be, you will be required to do that. I think Mac already does this on its own. So that's it for this. It's very easy, it's very simple. And in the next video will be downloading the IDE entelechy in order to style start typing our code. So I hope you enjoy it and I'll see you on the next one. 3. Downloading IntelliJ IDEA for Windows/Mac/Linux: Oh, okay, welcome back, my fellow developers. And this video we are going to be downloading intelliJ IDE. And we'll explain what ID is and we'll explain what intelligence is. So first of all, this is the symbol for the Intel J. And IntelliJ idea is an IDE. And IDE means integrated development environment. What does all of those complex words mean? Well, we'll use intelligence to help our computer understand Python language and compile the code. So basically what IDE does, it transforms the code that we write on the computer and allows it to understand it and convert it to bits and compile our code. So this is why we are going to be using IDE. Now maybe you already know what an ID is and you already have a preferred one. You can still use it to write Python. But in this course we'll be using the IntelliJ idea. It's a very, very nice IDE and it will be especially useful when it comes to debugging. Now, let's go ahead and download it. And of course, first of all, we'll open up the Google Chrome. In here will simply type in the search bar, download Intellij j. And you should get these links right here. And you should go to the WW dot jetbrains.com. And this is the official website for the intelligent. So we'll go in here. If you are on a Windows, you should get these dot EXE files. If you're on a Mac, you should get a different file type. And we have two ones right here. You can see the Ultimate Edition and the community. You can click in here for the Mac OS and Linux. But the ultimate edition as a addition where you have to pay if you want to get the special edition, The Ultimate Edition, go ahead and do that. It has a couple of features, but we are going to be using the community one which is completely free. So we're going to go ahead and download the community. You should get a file like this one. When you double-click on it, I'm not going to run it because I already have it installed on my PC. So during the installation, you might be shown the following window. In here. You need to make sure that you know what type of PC you have, whether it's a 32-bit or a 64-bit, if you have a 64 bit launcher, simply click on the 64 and then click Next. Continue on with your project or your installation. If you have a 32-bit, make sure that to create the desktop shortcut, to have the 32-bit launcher and download and install the 32-bit JetBrains runtime. So make sure that you click on this one right here and on this box right here. And then finally, you will be, at some point, you will also have to, of course, accept the surfaces and terms. And then you'll have this window right here. A sharing. I won't be sharing any data if you want to, you can. It will maybe help solve a couple of bugs that you might encounter. But I recommend that you don't send the information and that's all for installing. Now when you finish, you should get prompted to a window, just like this one. So let me just show you. You should be prompted to a window like this one. It might be just a little bit different if it's your first time using intelligent. But for now, you should have the same tabs right here. You can go to Customize. You can choose whether you want to use the intelligence, a light, or the Dracula, or any other font or color theme that you want. You can also change the font on your editor. I'll be using a bit of a bigger font, so you can clearly see it on the window when I type, you can use a smaller font. Bigger font depends on your preferences. Now, in the next video, we are going to be setting up the environment on IntelliJ. And we of course, are going to be downloading a plug-in in here, which is Python. You can go ahead and start with that so you are ready in the next video. With that said, I hope you enjoyed the video and we'll continue on setting up our environment and start writing Python. And then next one. So I'll see you then. 4. Setting up IntelliJ IDEA: Welcome back, My favorite developers. And this video we are going to be setting our environment up for Python and we'll start creating cold later on. So first thing we'll need to go into the plugins. And in here you should search for Python. You should find the Python community edition and go ahead and download it and install it. This will allow our intelligence IDE to understand Python language and you should see it right here in the installs. Now the next thing we need to do is we need to set up our SDK as decay means the means the software developer tool. And this is actually what will allow us to write the code more efficiently and create files that are of Python. But so in order to do that, let's go into the projects. You may be, you may have a different layout. Don't worry about this because I've already used Intel J and already created new projects and so on. So if it's your first time, you might have a different layout, but you need to find the new project and go ahead and click on it. Now, op here, you will see that we have the project as decay. You might not have the Python three gold mine right here. If you do, that's great. You can continue on. If you don't, you should click in here and intelligence should find the path to the Python 3.9. If you also don't have in here, we have to add it manually. So let's go ahead and add Python SDK. And here you should find the location currently it's in here for me. Make sure that you are on a virtual environment or you have this tab right here clicked, find the location of the environment where Python has installed it. It should find that automatically if you've installed it correctly from the previous video. But just in case it's not unique to find it manually on your PC. Make sure that you click on the inherit global site package and make sure that you have, you make it available to all other projects. Then go ahead and click on Okay, and everything should be working great. Now in here, everything should be set up and working. In the next video, we are going to start writing our first goal. So I hope you enjoy it and I want you to put your full thinking caps, give me your full concentration. And let's start this journey to gather. I'll see you in the next. 5. Section 2 - Getting Started In Python: Our First Python Program: Welcome back, my fellow developers. In this video, we are going to be doing a lot. We're going to create a new project. We're going to create a new Python file. We're going to learn what a five by five is. And we're going to print our first line to the console using the brand new Colt of Python that we are going to work. So let's not waste any more time and let's get started. Okay, so in programming, whenever someone is learning a new language, it's a tradition to create your first program to be hello world. So that's what we are going to do. So we've already set up the SDK, we've already set up the Python plugin on intelligence. Now it's time to create a new project. So lets click on New Project. And here you should have the project SDK as Python 3.9. Let's go ahead and click Next. And in here we're going to call our project Hello World. And you can actually add spaces whenever you are creating a new project, but not when you're creating a new file. So we can add spaces with project names. That's click on Finish. And okay, here we go. So as you can see, you should have this panel right here, which is for your projects. And you can currently see that the hello world has the idea. This is for the intelligence and the hello world, IML. This is simply for python projects. They have this file. No need to worry about that. Now the next thing we're going to do is we'll create a new Python file and an order to do that, we're going to right-click in here on the Hello World and go ahead to New. And you can see right here that we can create a new Python file. So let's click on that. We can name this whatever we want. But for the sake of simplicity, we always name our files based on what we are going to inside of them so we can easily find them and know what this file does later on. So we're going to name this Hello World and hit Enter. Great. So now as you can see in the HelloWorld project, which is located on the D python projects Hello World. This is something that I've created. You can change the location. And in here you can see that we have the Hello World and it's open right here. We can double-click on here in order to have it full screen. Or we can simply close this window right here. Now before we start coding, I just want to explain what Python files are and what is the extension dot py or PI is. So back in our slides, let me put on the laser. So what is the dot py file? So we have the Python already installed on our PC, but it's only able to communicate or project or be compiled on our PC because of the intelligence that we are using or the ID. Now, it does not communicate automatically with intelligent. It actually needs to have this dot py file in order to be able to get compiled for the intelligent idea to understand everything. It knows that the Python code is written on the dot py file, and that's how it compiles everything based on that. So the only thing that you want to know, this is not very complicated. Whenever we want to write Python on intelligence or any other IDE, we use the dot py file. Okay, great. Now with that explained, Let's go back to our intelligence ID. And in here we are going to write some code. So what we want to do is we want to print to our console something that says Hello World or a sentence that says Hello world. So first of all, let's start writing print. And as you can see immediately intelligence starts giving us suggestions of what we wanted to write. So p, or it immediately senses that maybe we want to write print, and it's correct. Whenever you get the suggestion, you can simply click on the tab and you can see that intelligence continues the work for us. Now we're going to open up these two brackets in here. And in here we're going to write hello world with an exclamation mark. Great. Now, if you see this little squiggly line, this means that we need to press Enter and this little squiggly line goes away. We're going to right-click in here and we are going to run Hello World. So when we hit run, you can see that it prints out in here, Hello world. And you can see the input and this little box right here that opens up a new. So great. This is a very simple example. Now it's time for your challenge. Your challenge is going to be to print a personal message. So first of all, change the printed line from a simple Hello World to say hello, for example, with your name on it. Run the program, and make sure it works without any errors. And I want to you to congratulate yourself on your first Python program. So pause the video right now and go do the challenge. Okay, welcome back. How did you get on with that? So we're going to change the Hello World to hello Michael. Thank you for teaching Python. With an exclamation mark. We can right-click and hit the Run, or we can immediately click on this Play button right here. When we hit play, we can see that it says Hello Michael, thank you for teaching Python. So I hope you enjoy it. And the next video we are going to be dissecting the sprint method and function, and we'll see what it's made of and how we write it. So I hope you enjoy it and I'll see you on the next one. 6. Printing in Python: Welcome back, my fellow Python developers. In this video, we are delving deeper and to print. So as you can see in here, we've added multiple prints. We've added prints with numbers, prints with strings, prints with a single argument, prints with no argument at all, and prints with multiple arguments. And we've printed all of that on this console right here. So let's not waste any more time and let's get started. Oh, okay. So print is a function that allows us while, as it says, it allows us to print anything we want inside of these two parentheses, parentheses. But we don't need to put double quotes. For example, we can print. And instead of using double-quotes, we can use a single quote in here. And we can write hello there. Python learners. And if we hit run, we can see that it also prints the same, but make sure that you only use one of these, so you cannot use a single quote and two quotes at each end. You need to make sure that you either use two quotes or a single quote. Now, the good thing also about print is that you can not only print words or strings, as we'll learn later on, you can also print numbers. So what do I mean by that? If we come back here, we can use the print. And we can print, for example five. So if we print five, we had the Play button right here. We can see that we print a number five. Not only that, we can also print, for example, 12 plus 23, and we can add spaces just for the readability. Readability. We hit Play. You can see that 12 plus 23 is 35. Great. So we can also print nothing and this will add a space. And in here we can say that this is the end. When we hit play, we can see that we have a small space right here. We have the hello Michael V. Hello Python learners. And even though we have a space in here between each sprint, we don't have a space in between these two lines right here. And this is very important to understand. White lines or empty lines such as these don't register and the code. So as you can see, there is nothing and nothing changes. What else can we do with our print? We don't have to send only one line in order to print it. We can send multiple lines. So in here, for example, this is the end. We can add another line or fed me, just call this by its right name. This is an argument and we'll learn more about arguments just in a little bit. But for now, we can add a second sentence. For example, nope, I was getting. And then we can add also another one using a comma in between them. Let's remove this space in here. We are just getting started. So now when we hit play, you can see that this changes from this as the end to this is the end. No pie was kidding. We are just getting started. And another thing that we can also do is we can add a third argument and which is a number, which can be any number. So for example, 15, if we had Play, you can see that this is the end. Nope, I was kidding, just getting started and 15. So we can concatenate multiple strings, or let's say words, multiple arguments, and print all of them on a single line using a single print. So let's go ahead and bisect the sprintf method and see how it looks. So how a function works. And by the way, I'm using both the both worlds function and method. You can use them interchangeably. They are the same. So for example in here, this is the print, this is the function name, so the name of our function is print. Then we need to add the argument which is inhibited. This argument, as we saw, can either be a string, which is a string of words, of characters, or it can be a integer, just like the number that we added. Or it can be also a float. And then we have the brackets. So every function name has, every function has a name, has the brackets. And in-between those two brackets we add our arguments. So with all of that knowledge in your head, it's time for a challenge. So your challenge is to combine everything that we've learned. First of all, print a line where you combine both words and numbers. Make sure to use a comma in between them. So use a common between each argument that we add. And finally, run the code and without any errors. So pause the video right now and go do the challenge. Okay, welcome back. So in here we are going to write a line. So I'm going to use print. I'm going to open the double-quotes. And we're going to write, if we add six and comma eight, open the brackets, we get 14. Let's go ahead and hit play. So if we add 68, we get 14. So I hope you enjoy it. I hope you learned what print is and how it works. I hope you understood how we can sometimes send a single argument of a string or a single argument as a number. We can use print to add stuff up. We can send no arguments at all, or we can sell, send multiple arguments separated by a comma. So in the next video, we are going to be delving deeper into strings and user input. I hope you enjoy it and I'll see you in the next video. 7. Strings in Python: Welcome back, my fellow Python developers. In this video, we are going to learn about concatenation. We are going to learn about getting input, and we're going to learn how we concatenate inputs. Most of all we're going to learn about string variables in Python. With that said, let's not waste any more time and let's get started. Oh, okay, so first thing we're going to do is we'll create a new file. So we can go in here, right-click, go to New and click on Python file. We are going to call this string variable. And when other groups, whenever we are calling a Python file, as I've said, we can't put a space in between them, so we can use an underscore. So string variable hit Enter, and let's double-click on here and get started. So first thing I want to demonstrate how we print. So we can use print, we can use double quotes as we've said. So we can, so we can run Forrest run or we can put it inside of a single quotes. So print a single quote, we can write. Python is really easy to, oops, easy to Learn. And if we hit Enter, we can see that for some reason a different program or the previous program is being run. And that's because if we look up here at the top right corner, we can see that the program that is about to be R1 is the hello world. So in order to change that, we can simply right-click in here on our string variable file and hit Run. And now you can see that the file which is string variables is being run. And finally, what I wanted to show you is that we can add both of those together. So for example, if you write print, we can include double quotes inside of our print and just make it like this. And, and as you can see, intelligence is very good. It notices that there is a typo. We can right-click, Show contexts, actions, and it gives us some options that we can use. Now when we hit play, we can see that we can include double-quotes and we can also include single quotes, but the other way around. Okay, great. Now let me show you what is concatenation in Python. So for example, we can write print. We can add hello. And then we can add a plus in here. And then world. And when we hit play, we can see that it is printed on a single line and make sure that you add a space in here because if you don't, they will be smushed together. And concatenation is a very powerful tool. And why am I saying concatenation and not adding? Well, because we are not actually adding both of those, we are concatenating them to cut together. If we use numbers instead of strings. Then we are going to add them inside of the. So until now we have been only using our string variables immediately or directly inside of the print. But a very cool feature of Python and other programming languages, of course, is variables. So what we can do in here, we can actually store a string inside of a variable. So I can write, for example, in here message, and this is how we create a variable. And I can now give it a value. And based on that value, the message will have a certain part. So for example, if I write message equals 5, the message will become an integer. I write message equals hello there. With a space, the message becomes a string. And this is a feature that is only available in Python and some particular languages. For example, if we are writing in C plus plus or in C, we need to give it the type of message or the type of variable which is named message. So based on what we give the message at B, it has the type. And now we write a, another variable which we will call name, and we'll give it Michael. So now name is also a string variable. And finally we can print message plus name. And if we hit Play, we can see that we have typed hello there, mike. Very nice. And finally, a, another very useful tool that we can use and Python is getting input from our user. So for example, instead of simply writing Michael, and here we can actually say that we want the input. And you can go and choose the input. And here you can hit tab and you can add a message in here. So give me your name. And now when we hit play, you'll see that the program won't stop running until we give it a certain input. So in here, I can say Jeff. And now when we hit Enter and here you can see that instead of name being just Michael, it is the Hello there, Jeff. So you can give it whatever name. And this makes it more dynamic and of course, much fun and looks much better. So now it's time for your challenge. And your challenge is to print out your own inputs. So get two inputs from the user, a string and a number, and concatenate them together and print them to your console. So you'll need to be a little bit creative. And here, create a certain sentence that has a number and a string, concatenate them and get the inputs from the user and, or the user of your program. So pause the video right now and go to the challenge. O K. Welcome back. So let's go ahead and write in here print. Please type in your name and a number. We're going to hit Enter. We're going to write name. Or because we have already a name, we can actually override it. No problem. We're going to write input. The name is. And then we're going to get a number. And we're going to write input. The number is and we're going to print. And we're going to write, oops, I meant name, which is our variable that we are going to get up here. We are going to concatenate it with another string, so just ate and the number. And then we'll concatenate it again with a string. And what did he eat? A chocolate bars. So chocolate bars. Chocolate, Very nice. So now let's go ahead and just remove this for now. Let's remove this for now and remove this also. Hit Play. And now please type in your name and a number. And before I do that, let me just print this in order to know where we are. Yes, stop and return. So now we have a space we know where our challenges please type in your name and a number. So name Michael, number 68. And Michael just a 68 chocolate bars, which I'm sure is some kind of record. So I hope you enjoy it. I hope you will learn. I hope you are doing your best and the challenges because as I've said, learning, not just about watching, I don't want to just staring at me creating programs and then piping. Besides me, this is not enough. You need to do your best in the challenges. And as you saw, even if you can't figure out how to do the challenge, I'm always there to the challenge after you've tried and it's much better if you already tried and failed, and tried and failed and then you see the solution, it will stick in your head much. But with that said, I hope you enjoyed. And in the next video we'll learn about special characters that we can use inside of print. I'll see you there. 8. Special Characters: Welcome back, my fellow Python developers. In this video, we are going to be learning about special characters called escape characters. So as you can see in here, we've created several lines of different things. We've added, we've added this backslash d, backslash, backslash, single quote, backslash double quote. And as you can see, this will be your challenge in here that you shouldn't be seeing. But anyways, let's not waste any more time and let's get started. Okay, so escape characters are special characters that allow us to do certain things with the strings that we have. So let's now talk about this. Let's demonstrate this. So we're going to create a new Python file in here, and we're going to call it escape characters, or escape character. Doesn't matter. Whatever you want, just make sure that you indicate what the file does. So in here we're going to create a variable called split. And this split is going to be equal to this string has. And then we are going to put a backslash in here and several backslash n lines. And so now if we print split, we run the program. Of course we are running the previous one. We right-click, we run this one. And you can see that this strong, this string has several lines. And wherever we add a backslash and we can see that we go to a new line. Let's hit play again just to make sure that we corrected this. Okay, now what else can we do? We can also tab. So we were going to create tabbed is equal to this string, is tabbed several times. And let's go ahead and print, dabbed, hit play, or run the program. And you can see that this strong, again, I can't seem to hit the I key. So this string is, and you can see that there is a tab right here, which are several spaces in between and several times. So this string is stabbed several times. Very nice. Now, this backslash is actually what allows us to differentiate between normal characters inside of string and special characters. So we can also use this and what's the problem? Okay, so maybe this is wrong. And we can also use this in order to print single quotes inside of strings that have already a single quote. So let me show you what I mean. So for example, if I write print, he was screaming. No. Please. It was if we put a single quote in here, the string or the principal, think that we have already finished typing, but we have. So what we can do is actually add a backslash in here. Jordan. Backslash. He backslash is the one who jumped. And then we add a point at the end, and then we finish the quote. So as you can see in here, if we hit play, we run the program. He is screaming No, please. It was Jordan. He's the one who jumped. So as you can see, we can actually add a single quote right here. Let's go ahead and duplicate this line. And the way we duplicate a line, as we can go to the end of it, click in here and hold Control D. And you can see that we duplicate the same line. And you can do this as a challenge. What we want to do is we want to actually wrap this all around to double-quotes. And then we want to fix all of this mustard we have. So in here, we can add a single slash. In here, we add a single slash and we can actually remove these slashes in here. Again, when we hit play, we can see he was screaming No, please, it was Jordan. So we have the same output, one and a single quotes or double quotes. Okay, Very nice. So now that you know how these special characters work, It's time for your challenge. And this challenge is going to be a bit tricky because you need to print a link. So print anything you want to our console. And the trick here is that we want to actually print the backslash. So that is a very cool challenge for you. So there are two ways to do this. One is very obvious. I'm not going to say it, but you should already know what it is. The second one is more tricky and needs research for the ones that are there, that are savvy and want to challenge themselves. This is a great opportunity. Other than that, pause the video right now and go do the challenge. Oh, okay. Welcome back. How did you get on with that? I hope you at least found one way. So in here we're going to print an empty space. We're going to print. And this is the easy part. So www dot python, he has by fonts.org. And we're going to slash slash, terminator slash slash. Nothing else. Of course, this is a very fictional link. So now when we run the code, we can see that we have python.org and we can actually print the slashes. Now, another way of doing this is writing in here, Python. And if we copy this entire line, we should have duplicates that. No worries. We can actually remove this. You'll see that if we hit play, we actually add a tab and we add a second line using the slash right here and the slash right here. And that is a huge problem. So the way we can fix this is by adding an R to the beginning of our strings. So when we hit play, you can see that WW dot.org slash, terminator slash and nothing else. And this R tells the print function that this string should be printed without any special characters, and r represents here, Rob. So with that said, I hope you enjoy it. In the next video, we'll be learning more about variables. I'll see you there. 9. Variables and Types: Welcome back, My favorite Python developers. In this video, we are going to be delving deeper into variables, will learn the different types of variables. We'll learn how to print out the types of variables that we have. And we are also going to learn a little bit or get introduced to what comments are in Python. We'll delve deeper into those later on with that said, let's not waste any more time and let's get started. So we've seen what variables are in previous videos, but let's delve just a little bit below the surface and see what they actually are. So what are variables? While variables are just like boxes? So let's say we get a box and we name this box lives. And what we do is we actually put some data inside of it, for example, three, and this becomes a variable that has the value three inside of it. And we can create it using this syntax and our code. So for example, the variable name is lives and the data inside of it as 3. And Python is unique in the sense because unlike other programming languages where you have to determine what the variable type is before you instantiate it. In Python, you can actually give it the data. And based on that data, the variable will take a certain type. So let's see what types of variable we have in Python. So for example, we have the float variables. And float variables are numbers with which have floating points. So for example, 4.83.968.7, those are all thought variables and they are used, for example, in velocity where, you know, velocity doesn't need to be, for example, 10, 12, 11. It sometimes can be 11.211.3. So float variables are very essential. Then we have Boolean variables which take two forms, either true or false. So for example, if we want to determine if somebody is dead, if it's true or if it's false, it can be 2.3, for example. And finally, we have the string which we have already used, and of course the integer that we showed previously and strings we already saw, these are a string of characters. So for example, the word or the name Michael is a string and we put it inside of the box, which is named my name, and we have a variable. Okay, great, so now that we took this little dive into variables, let us go ahead and actually type so on. So back in our code, Let's go back into our string variables. And we already saw with create the message right here and the name and numbers. Let's go ahead and remove or actually comment this out. And the way we comment is we hit the Control backslash and all of these are commented out. We'll talk about comments more later on, but for now, these everything that is commented out will not be working. So let's create a variable in here. We'll call it h, and let's give it a value of 25. So now because 25 is an integer variable, age is of type integer. Let's go ahead and print out h. Let's run the code. Make sure that we run the strings underscore variable. And you can see that we have 25 and here. But how can we actually make sure that age is a integer? Well, there is a very helpful tool in Python to do that. So if I write print, we then write the type and then add H to it, and then run the code. We can see that it prints out the class type of our integer or our variable and it is an integer. So great, we are on the right track. Let me just uncomment the message in here. And you'll see that if we try to print out the type of the message. So print type message and run the code. You'll see that message is actually a string and I mean a string variable. Very nice. And this allows a very dynamic use of Python. And why is that? Well, because if we now add two parentheses or two double quotes around the data that is going into h. This creates a string, but now when we run the code, you'll see that we have the same output of 25, but now instead of an integer, we have a string. And this is a very powerful tool only unique to Python and other coding languages. You need to actually specify what type of variable you want in age. And if you give it a different type of variable, you will have a different outcome. While Python, because as we've said in the beginning, it's a very versatile programming language. It focuses more on readability and ease of use. That's why it's more dynamic just like this. So now that we've learned that we have different types of variables, we've learned how to change them. It's time for a small challenge. Your challenge is going to be to create and print variables. So first of all, you need to create a float, integer and string variables. You will then need to print them out using the print. You'll need to print out the type of each on a separate line. And finally, you need to make sure they match what is given to them. Now, I haven't added this, but you can also create a Boolean type and see how that looks. So pause the video right now and go do the challenge. Okay, Welcome back. So let's go ahead and also remove all of this. We're going to create three variables in here, and we'll also comment this one out. So we'll add this. I use a control and backslash in order to add a common. So in here, what we're going to do is we'll create three variables. So a number, float. And you'll notice the way I'm naming my variables. So whenever you want to create a variable, you never start off with a capital letter. You always start off with a lowercase letter. And then as you move through, each word needs to have capital or an uppercase letter in front of it. Or you can use, for example, underscore, number, underscore, float. It depends on your preference. Everything, there is no mistake in here. It's just a more convenient way of naming your verb. Now we're going to create a variable of type integer, so a number. And, and we'll make this 14. And finally we'll create a string. And it's going to be equal. Love the scores, and give it a five. Stores review. Okay, So with a Smiley face, and this is totally random. I just thought of the string on my own. And now let's go ahead and print all of these to our console. So first of all, we're going to print the type of our float, so a number float. We're then going to print the type of the integers. So a number and, and teacher. And finally, we're going to print the type of a string. And now if we run our code, you'll see that we have a float and integer and a string. So what that done, I hope you did the challenge. I hope you enjoyed it. I hope you have better understanding of how variables are initiated, how variables work, and the different types of variables that we have. So with that done, I'll see you in the next video. 10. Something To Watch Out For: Hey, welcome back. So just one thing that I wanted to mention before we move on, even though it's very easy to change the type of variable based on what we give it. We still have to be very careful on how we approach this. Let me just show you what I mean. So for example, let's say we want to concatenate our float with our string. So let's say we are going to print, let's say, and here the a string plus is, Let's use the a number. And for example, and let's add another, another string in here. And let's say is very good. This is just an example you don't need to type with me. I just want to show you what happens right now before you run the code. So if we run the code, you can see that we have an error in here. And this is very helpful. This is why we are using an IDE. It tells us on which line we have the problem and what type of error we have. And it's, the type error is on line 22 in here. And it's a type error. And it tells us that we can only concatenate string, not integer to a string. So this is very important to understand. We'll figure out how to deal with that and how to concatenate integers with strings and so on later on. But for now, I just wanted to show you that even though you can easily change the type of variable, you cannot easily concatenate different types together and you have to be very careful how you approach this. Now, let's take a few moments and explain what, what comments are. So for, as you saw right now, I commented out all of these and they are not showing up on our console. And I've used the Control backslash before, I actually meant the control front slash. And what control front slash does is it actually comments out something. And whenever something is commented out, it is not registered to the IDE that this line needs to be compiled, so it does not even enter. So for example, let's say we are, let's uncomment this. And the way you uncomment it is, you also use the control front slash. So for example, let's say we have the EIN number float. If we comment this out, you'll see that we get a small red squiggly line under the a number float. And this tells us that it's unresolved. And this means that we don't actually have a reference to this flow. This means that the IDE does not recognize or can't find a number, float anywhere because it's commented out. And comments are usually used for note for us later on. So for example, we can add a comment in here manually by adding this hashtag and telling us this is just a float number to demonstrate. And comments are very useful whenever we are writing code that is a bit complicated. So when we come back to it later on, we easily can understand what is happening. Or for example, we can create a comment in here that says, this was a challenge. So this tells us that everything under here is or was a challenge. We can also add a comment in here. This code doesn't work. So this is it. We don't have any challenges for you today. I just wanted to show you a couple of things to make sure that I'm not teaching, teaching you something that is, or you might try something and it comes out wrong and you might be asking, why is it coming out wrong? Didn't Michael say that this is a very versatile language? Well, some things you need to make sure you don't do. Okay, great. In the next video we'll discuss numeric type variables like float and integer. We'll delve deeper into those. I hope you enjoyed this little video and I'll see you in the next one. 11. Numbers Operators: Welcome back, My favorite Python developers. In this video, we are going to create a small calculator. So as you can see, if we give this two values, we get an addition, a division, a multiplication, a division and to the power 2 will also learn how we can get integer inputs in our code. And it's going to be a lot of information, a lot of fun and very important information to learn. Let's not waste any more time and let's get started. Okay, so first thing we're going to do is we're going to create a new Python file in here. So we're going to create a new Python file and we'll call it numbers. Double-click on here. And now we have a new file. We're going to create two variables, a, which is going to be equal to 35, and B, which is going to be equal to five. And these are now two integers and we are going to use a couple of operators and immediately start printing to our console. So first of all, we're going to print a plus b. And we're going to duplicate this line. And the way we duplicated as we actually go hold Control D, and we can see that we have the same exact code, but on a different line. We duplicated it. We can also copy and paste this, but duplicating it as much cooler. So now we have a minus b a times b. We get also a divided by b. We also want to have a divided, divided and you'll see what this does. And finally, we are going to go ahead and use a modulo. Works the more glue. Okay, great. Let's right-click in here. Let's run the numbers and you'll see that we have a plus B is 40. A minus b is 30 times it's 175 divided, it's 7. And when divided, divided, you can see that we have a seven and modulo returns the rest after the division. So what this to divide symbols do, they actually return the integer of the division. So let's say for example, we have four in here instead of a five. You'll see that whenever we divide 35 by four, we get the 8.75. But if we use the second divide, we get on the 8th and you can see the rest of the division. So what is the residue of the division is three after we divide 35 by for. Okay, great. Now in order to demonstrate this even further, let me just copy these two lines. And in here, I'm going to actually use type. And we'll put this in here. And we'll also use type in here. So where did the ego? But let's put the a back in here. Remove the whitespaces, add a space, and here we'll also add an empty line. So we run the code. You can see that if we simply divide a by b, we get a float. If we use the second, divide, the second forward slash, we get an integer. Okay, great. So now the true saw how we can use operators in our code and print them out. I think it's time for a challenge. And your challenge is going to be to operate on inputs. So first of all, you need to get two inputs from your user. You'll need to use addition, subtraction, multiplication, and division. So basically you are creating a calculator. You'll need to research how to calculate the power python. And I'm going to give you a small hint right now, because whenever you want to get inputs that are integers, you need to use this end first. So you'll need to type, first of all, end, open up the brackets, and then you'll need to get the input from the user. We've already covered inputs and I'll tell you why this is important later on. But for now, pause the video and go do the challenge. Okay, Welcome back. So let's go ahead and comment all of this out. We comment using the control forward slash. Let's get two inputs. So first of all, we're going to write print. Please give me two numbers. Then we're going to write a equals int. Just as I've told you, the civil make sure that we get an integer. Or to be more precise, we will convert the input to an integer and not get a simple string. And he, and here we'll give a. And then we are going to get the nth input B. And we're going to go ahead and print a plus b, a minus b a times b a divided by b. And finally to the power 4. Some of you that have researched this, in order to make a to the power b, we simply add two multiplication symbol, so two stores. So now if we run the code, this gives me two numbers, a, let's say 12 be, let's say three. And we get 12 plus 31512 minus 3, 9, 36, 4.012 to the power 3, it's 17, 28. Okay, great. Now a small problem in here. First of all, what happens if B is a 0? So if we run the code, let's say a is 324 and b 0. As you can see, there is a problem because we are dividing by 0, and this is a huge problem and programming, we'll deal with this later on. Another problem we have is if we remove the integer from here, let's remove these. If we had, if we run the code, let's say a is 23, b is 65. You'll see that we also have another pipe error and we get an unsupported operator. It's online, 19, It's in here. And it's exactly what we tried to avoid in the previous video. What we tried to look out for. We cannot concatenate a string with an integer. And here is the biggest proof of that. So whenever we are writing an input and we need it to be an integer, we need to convert to an integers in order to not have it as a string. So let's run this code again, make sure it's working. And Yup, that's a very big number. In the next video, we will look at operator precedence. So let's say we have a plus a minus a times and a division on the same line, which takes precedent over which this is a very important video, even if you think that you already know how to do this. But that said, I hope you enjoy it and I'll see you in the next one. 12. Operator Precedence : Okay, welcome back. So what do I mean by precedence? First of all, let's go ahead and comment all of this out and up here, Let's go ahead and remove or uncommon a and B. And let's go ahead and print something in here. So we're going to print a plus b divided by 3. Oops, I mean divided by three minus 3 times 4. Now, think about the answer and then check for the result. Let's hit the Run button. And as you can see, it's 24.3336, which is a very not obvious number. So let's maybe change this to five. Okay? So as you can see for 33 and B3, I wanted to choose very good number so we know what's happening. So what do you think is happening in here? So first of all, we are starting off with B divided by three. So we're taking the three divided by three, it's one. Then we are doing three times four, which is 12. So this is minus 11. And then we are subtracting this or this becomes 33 minus 11 and we get the answer 22. Now, if you thought that you might get a different answer than, I guess you haven't been paying attention at school. But as you can see, the laws of mathematics in elementary school apply in here also. So in order to better understand what is happening, we can add a parenthesis and here. So 3 times 4, b is divided by three. And this should give us the same answer. Very nice, but if you want, you can actually get a different kind of result. So let me go ahead and put a parentheses in here. So a and B get calculated first, and then they are divided by three, but not just any three. It's three minus. Let's say I wanted to put in three, but this gives us, that's put a four in here. So it's three minus four, and then it's times 4. And obviously we have some kind of error in here. What does it show context? Also, we need to add one more. Oh, should remove a parentheses. Okay, so let's go ahead and run the code right now. And you'll see we get minus 44. So I have no challenge. But what I do recommend is that you play around and understand how parentheses affect the presidency of our numbers. And this will be very important when we start working on if conditions and when we try to create specific conditions to work, we'll need parentheses for that later on. With that said, I hope you enjoyed the small video and I'll see you in the next one. 13. String Data Type: Welcome back, My favorite Python developers. You might be thinking right now, why do we need to learn about strings, Michael? I already know everything about strings. While no young grasshopper, we actually have a lot more to delve into when it comes to strings, as you'll see right here, right now, Let's not waste any more time and let's get started. Okay, so let's first of all go ahead and create a new Python file. And we're going to call this pile strengths. So double-click in here and let's start off. First thing we want to do is we're going to create a variable that is message. And this message is going to be, Python is a great language. And let's not make this capitalised. So Python is a great language. Make sure that you type this correctly. Next thing we're going to do is we're going to simply go ahead and print out message. So right-click run strings and you can see Python is a great language. Now, what else can we do with this message? Well, strings are actually deeper than you might have thought. So what we can do is we can actually index through this entire string. As I've told you before, a string is actually a string between characters. So you string multiple characters together and you have a string. So each character in here can actually be printed out separately. So what we can do is we can actually print message and we can actually index through our string using these two square brackets. So for example, if I want to print the y, I can go ahead and type in here one. So if I run this, you can see that y is printed. Now you might be thinking, why are we not using 20 and here between the parentheses? So in Python and most languages, the indexing starts at 0. So if I want to print DPI or PPI, I hit play. I get the word P or the character p. So in here, let me just show you what I mean. So we're going to number all of these. So 0123456789. And when we get to tn, that's at a another comment in here. So this becomes one. And again we start off 123456789 and then we get 2. And here, and again, we have 1234567. That's it. So as you can see, for example, we want to print the Iike, it's 15. So duplicate this. No worries, We get 15. Hit Run. Let me remove this one, run the code and we get a. So, oh, okay, So I started the 0, 2, 3, 4, 5, 6, 7, 8, 9, and then again with a 0. So let me just remove all of this and add one and here, so 0, 1, 2, 3, 4, 5. And now if we want to get the in here, we can write 14 at play. And we get the Iike. For example, we want the u in here. Let's go ahead and get the EU, it's 20 to 22. Run the code, we get you. Everything is working perfect. Now that you've learned all of that, it's time for a small challenge. And your challenge is going to be to print out a message differently. So use the message that we have to print out another message, which is going to be, you are not using the indexes of our original strength. So pause the video right now and go ahead and print out. You are. Okay, welcome back. I hope you're taking this course with a significant other. Let's go ahead and print you are hot. First of all, let's remove this in here. Let's add, print an empty line, and let's go ahead and print out first of all, the U. So we need a y. Where do we get a Y? It's the index one. Then we need a four because it's on the o. Then we need a know what let me just Then we'll need where is it? 22 because we get the you will print an empty line. We're going to, oops, sorry. I mean, let me just copy this, put it here. Now we need you are a, it's at position 10. We need an R. So you can get whatever we're, whichever all you want there is only one R. So it's 13. And then an E, which is immediately after. Then we print an empty line. Then we again Need you are h, so h is at 3, 0, which is immediately afterwards. And finally we need another two. So let's run the code. Let's see, yup, you are hot. So I hope you enjoyed this video. I hope you enjoyed the challenge, and I'll see you in the next one. 14. Negative Indexing in Strings : Welcome back, My favorite Python developers. In this video, we are going to learn how we can actually index through our strings using negative numbers. So let's not waste any more time and let's get started. Okay, so we can actually index our string with negative numbers. So let me show you what I mean. First of all, let me just comment this out. And for example, let's say we want to get the lateral view using negative indexes. So we are going to print is that we are going to print message and we are going to index. So in here, minus one, minus two, minus three, minus four, minus four. Let's see how that looks. Run the code. And as you can see, we get the latter. You, Let's say we want to get the letter, let's say g, The first one. So minus1, minus2. We can go ahead and get the minus2 at play or run the code and you can see we get U, G, and that's it. So basically you can go ahead and wrap around your string and get the characters using negative numbers. So now that you have this information in your arsenal, it's time for a small challenge. And your challenge is to use negative indexes to print out the same message you are hot as previously in the last video. So pause the video right now and go print out you are hot using negative indexes 0. Okay, welcome back. So first thing, we're going to remove this and I'm going to use a very sneaky shortcut. I'm going to uncomment all of this. And some of you may have got the steel while doing the challenge. And here we have 26 numbers. So what we can do instead of going ahead and finding each in here. So each letter, which index it has, we can actually go ahead and remove 26 from one. And we can remove 26 from four, from 22. And we can actually do this operation in here in the indexes. Now this is not recommended because this will take a toll on the memory because every time it needs to go and search for the index, it needs to do another calculation. A better way of doing this, simply writing in here, for example, minus 25. Let's run the code and let's see what we get. You are hot. And as I've said, this takes a lot of computational power. So for example, if we write in here minus 23, it would be much better if we hit Play, we get the same output. So you are, I hope this didn't take much time. I hope you don't feel cheated that I didn't tell you about this small trick. But anyways, now that you understand what is happening and you can actually understand negative indexes will delve deeper into indexing in the next couple of videos. I hope you enjoy it and I'll see you. 15. Slicing Strings: Welcome back, My favorite Python developers. In this video, we are going to get a new name for all strings which are sequence type. We are going to learn how we can slice them using indexes, using a start index and index, not including, of course, and a step through. Let's not waste any more time, and let's get started. So strings are called a sequence type, which allows us to get certain characters inside the string. We've already covered that. But it also allows us to slice up our sequence and well, get slices from it. So let's say for example, we have this string to slice. We want to start at a certain position. So this will be the starting index that we want. We then need to give it a stopping position, which will be the stop index. By the way, if this is not included inside of this slice, will see a couple of examples of that later on. And then we can also add a step through. For example, we can slice using a single-step, or we can slice using two steps, three steps, five steps, and so on. So let's demonstrate this and coat back in our code. And here we can see that we have Python is a great language. Let me just comment this out and let's start coding. So in here let's say I want to slice just a little bit. We can go ahead and print the message, open up the brackets. Now, I want to slice from index 0, which is P, to index 5, which is m. Let me run the code and you'll see that we print out Python and Python. Although we did add a five in here, and this is what I meant by and not included. So the stop index is not included inside of the slice. Back in our code, you can see that if we want to include the end, we need to go ahead and slice from 0 to six, run the code and we get VM. So you can see this does not include the last one. The last character is not included. And this is important to remember because this occurs in Python in many different areas. So remember this up to but not including. So up to but not including. Okay, great. So now let me go ahead and slice, for example, let's say we want to get the word great. And the great starts at 12. So 12 and ends at 7017. Run the code, we get Python. And great, was that knowledge. It's time for a challenge. So your challenge is to print using slicers. So print out the word language by slicing our string and use two different methods. So one of them will be a bit more obvious than the second one. And let's see if you can do it. There is a small trick in here, and we'll see, anyways, pause the video right now and go give the challenge. Okay, welcome back. So some of you might have tried and failed because if you try to print the message and you want to print, let say, from 18, but this actually ends at 25. So what are we going to do if we run this code, we get language without the e. So what can we do? Well, we can go ahead and write 26 in here. And now when we run the code, we get the entire world language complete with it. See, now, what does the second method? Well, what happens if we don't give it a stop value? Well, in that case, you can see that it continues on until it gets to the last index in our string or in our sequence. So whenever you don't add an ending or you don't put a stop, you will actually go to the end of the index or the end of the sequence. And this is also true whenever you are trying to print from the beginning. So let's say instead of Python in here, instead of, I mean using 0, we can actually use a non starting value. So there is no starting value, which means it will start from the beginning. So when we hit play, we can see that we get Python. Python, even though we didn't add a start value. Very nice. Now I have a small question for you. What does this print out? So think really hard before you give me an answer. Okay, ready? Let's run the code. And as you can see, we get the entire string printed out. Why is that? Well, because we start from the beginning because we didn't add a starting index. We go until we get to the 18, but it's not included. So it actually gets here, this space. And then we again start message from 18, which is included until the last index, until the last character in our sequence. Now, I have another question for you. What happens if we try to print this? So think long and hard before you give me an answer. So when we run the code, you can see that we again print everything. This just tells the message or that there that we don't have a beginning and we don't have an end. So what it does, it actually starts printing from the beginning until the end. And we actually want to avoid this in the future and we'll see why until then in the next video, we are going to learn how we can slice using negative values. I'll see you in that. 16. Slicing with Negatives: Welcome back, My favorite Python developers. In this video, we are going to learn how we can slice our strings are sequences using negative indexes. With that said, let's not waste any more time and let's get started. Okay, so some of you may have already tried using negative indexes in order to slide. And I congratulate you for that, for those who didn't try, let's go ahead and do it together. So first of all, let me try printing this message. If I slice using minus 14, 2, minus 9, Let's see what we get when we run the code. We get the word, great. And why is that? Well, because if we go in here, minus 123456789, 10, 11, 12, 13, 14 until minus 9, which gives us minus 1, 2, 3, 4, 5, 6, 7, 8, 9. So as you can see, we can slice using negative indexes. There are a couple of rules. So for example, let's say I want to slice from a negative value to a positive value. Well, what do you think happens here? Think about it before I run the code. It doesn't print out anything. It's an empty string. But this is not entirely true because if I try slicing from minus 14 to 17, again, think of the answer. What do you think will get? Run the code? I get great. Now, why is that? Well, this prints out great. And that's only because the number 17 actually wraps around the entire string and goes over the index which is at minus 14. So minus 14 is on the G. Because for the example we used previously is in here. So we can't actually move from minus 14 and go to four. That's why we don't have anything printing out. But when we are using 17, we can actually move from minus 14 and slice all the way up to 17. Okay, great, so now with that knowledge, it's time for a challenge. And your challenge is to print using negative slicing. So first of all, print out the word language by slicing our string. But this time you can only use negative slicing. And a warning, there are a few traps in here that you need to watch out for. With that said, pause the video right now and go do the challenge. Okay, Welcome back. So let's go ahead and do the challenge. Let me just delete that. So in here we're going to print the word language. So some of you might have been tempted to write this. So minus eight and the index is minus one. If we run this code, you'll see that we are missing an e. And that's understandable because as we've said, whenever we are slicing, it's up to but not including. So some of you might have tried to maybe add a 0. So yes, minus 8000 if you run the code. Nope, As you can see, because 0 is here, minus 8 is on the, on the L right here. This means that we cannot slice through 0, is, does not wrap around. So how are we going to fix this? Well, there is a very simple way. We simply remove the 0 from here. So now when we run the code, we get the language sliced up from our string, ready to go. So I hope you enjoyed this video, the small little video, and the next one we will delve into the step we haven't seen yet. We'll see that in the next video. I'll see you there. 17. Using a Step while Slicing: Welcome back, My favorite Python developers. In this video, we are going to learn how to add a step whenever we are slicing through our code. So let's not waste any more time and let's get started. Oh, okay, So as I said, we also have the steppe who haven't used yet and now is the time. When we don't specify a step, we get the default one, which is one. So for example, whenever we are slicing and here it's as if we have this kind of syntax, but when we don't add it, it defaults to one. So let's comment this out and let's try it different steps. So first of all, we're going to print message and we are going to slice it going from, let's say, 0 to 17. And we're going to use a step of two. And then we are going to do the same, but we are going to use a step of three. So when we hit play, you can see these are the two outputs. How is this actually working? Let's go through it step-by-step and get it step-by-step. Okay? Anyways, first off, we get the p. How did this come along? So we start at the index 0 and we end at 17. We have the p. Then, because we are stepping 2 times, not just once we go from p, we go over the wall and we go to T. Then we go over the age who go to the 0. Then we go over the n and we have a space. And here we go over the eye, we get the S, We go over the space, we get the a, we go over the space again, we get G and you get it from here. So we are stepping two times, once over each character. Then we have three. So in here we have pH two spaces and GA. Let's see how that works. So we start at 0, we get the E, we ignore y, t h, we ignore 0, and we get the space. We ignore i. As we get the space, we ignore a space and G. Very nice. So I hope you're understanding how step is working. If not, I recommend you pause the video and go through it a couple of times to make sure that you get it right. Because we inherit, we are going to create some kind of data. Now, maybe some of you are looking at this and thinking why is adding a step even important will be even use it. Well, let me show you how it can be used. So let's say we have some data coming end. And this data is going to be six with a common than 36, five, a front dash, 321, a backslash, or a middle slash, mature, that's called. We get 984, we get a point, we get three for 300. Four, we get a nother. No, I mean, let's say we get some kind of character p and then 7, 8, 5, 9. So as you can see, we have data coming in, but it's corrupt because of these nasty, weird characters. So we only want the numbers inside of this data coming in and it's going to be part of your challenge. So your channel's going to be to print out the separators. So print out the separators and you step in slicing to avoid the numbers. So pause the video right now and make sure that you print out all the separators. Welcome back. So I might have said that we are actually extracting the numbers. Well, in fact, we are extracting the different characters, everything except the numbers. And this will be useful later on in our course. But for now let's do the challenge. So what we want, we're going to print and we are going to get the data coming in. And before we do that, let me just comment this out. So the data coming in. And because we are focusing on the separators, we are not going to start at 0, we are going to start at one. And because we are going to the end, we are going to leave the stop empty. And finally, we are going to use a step through of five because let's say we want, we get the separator, then we want to skip over 1234, and then we get the five. So let's run this code. Let's see if that works. Yep, we get the comma, the front slash, the middle sludge, the point and the letter p. So I hope you did the challenge. I hope it wasn't too confusing and I'll see you in the next one. But I just wanted to say why this is important and here, so because we are able to detect where our separators are, we will then be able to remove them and display only the numbers coming in. And this, as I've said, will be useful in later parts and our course. In the next video, we are going to learn how we can slice backwards using negative indexes. I'll see you there. 18. Slicing Backwards: Welcome back, My favorite Python developers. In this video, we are going to learn how we can actually slice backwards using a negative steps. So let's not waste any more time. There is a huge challenge at the end. So I want your full concentration and thinking caps on. With that said, let's not waste any more time and let's get started. Oh, okay, so first thing we're going to do is we're going to create a new Python file. Because this one is very cluttered. We're going to call this back underscore slicing and hit Enter create this new file. Double-click on the tab right here. And let's start slicing. So first thing I'm going to do is I'm going to create letters. And it's the a, B, C, D, E, F G H I J K L M N O P Q R S T U, V W, X, Y, and Z. Let's right-click Show the context. And nope, okay, so next thing we're going to do is we're going to create a, another variable in here. And we're going to call this reverse. And it's going to be equal to letters. And these letters are going to be sliced from 2005, yes, 25 to 0 using a minus1 step. So let's go ahead and print reverse. And before we do, I just want you to think about what the output of this will be. So let me just make sure Let's hit Play. And we can see that I forgot to run back slicing. And as you can see, we have this entire alphabet but in reverse order. And as you can see, the a is excluded. Now, just as a small challenge, as a mini, mini challenge. What can we change about this in here? An order to get the a. Of course, we can simply remove the 0 right here. And when we move our one, we run our program. We can see that the a is at the end. So what is actually happening in here? So as we said, this is the starting value and this is still true. So we are starting at index two IF which is up and it's included. And then because we are using a minus1 instead of going forward to the right, we are actually moving to the left. And this is why we are allowed to put a 0 or a five or anything less than 25 in here because we are moving backwards. So take a couple of minutes, seconds to understand what is happening in here and how we are moving backwards. And when you finally get it, when you find, understand what's happening and you are confident, you can move on to the challenge, which is to use your new superpowers, which is using negative indexes in and stepping. So print out, this is a huge challenge. You need to print out I, j, k. It doesn't need to be uppercase UT as all. And you need to print the last eight characters in reverse order. So pause the video right now. If you need a bit of time, go back, look at the code, understand how negative slicing works. Come back to the challenge and try your best. I'll see you in just a bit. Okay, Welcome back. So let's go ahead and create IJK. And it's going to be equal to letters. And the IJK is actually 012345678. So we're going to start at eight and go to 11. We're going to print IJK. Now let's go to UTS and we're going to use negative indexing. So negative step, I mean, so we're going to start at the end, which will be around, let's say 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, I think. Okay. So it's 16 and then we add four to it, so it's 20. So we are going to start at 20, go backwards to 16 using a minus1 step. Let's print UT us OR. And finally we want to print the last eight characters. So last characters is equal to letters, and we're going to print from the end. And then until if we want the last eight characters, we want to minus nine, minus eight, minus nine, and a step of minus1. So let's print the last characters. Let's run this code and see if that works. So IJK, UT ASR and Z, Y, X, W, V U T S. And these are 12345678, last characters printed and reverse. So I hope you enjoyed the video. And the next one we are going to be looking at string operators, not number operators, string operators. With that said, I hope you enjoy it and I'll see you in the next one. 19. String Operators: Welcome back, My favorite Python developers. In this video, we are going to learn about string operators. We are going to concatenate them. We are going to put them in weird ways. We are going to multiply them and them. And we're also going to learn how we can check if one of the strings is inside a, well, another string. So let's not waste any more time. This is a big video and let's get started. Okay, so first thing we're going to do is we're going to create a new Python file. And we're going to call it string of raters. Okay, great. Now here we are going to create five strings. So string1 is going to be equal to 1. String 2 is going to be equal to, does not. Strength 3 is equal to. Simply walk. And if you get the reference, I advise you to continue walk into. And the last one is Mordor. So hopefully you get the reference. So one does not simply walk into Mordor. How can we print all of the strings to gather on a sane, same or a single line. So we can write print. We can get string one, and we can cut concatenated with string2, with string three, with string 4, and finally string five. And if we right-click run string operators, we can see that one does not simply walk into water. And you can see the spaces in here are courtesy of the spaces that we've added here when we started creating. If we remove these spaces, we concatenate the strings. You'll notice that, well, there is no space between them. Okay, great. But what can we also do? Well, there is another way to concatenate strings. We can go ahead and simply write, Hey, space. And even without adding any commas there, My name is Frodo Baggins. If we run this code, you'll see that these strings that are not separated by anything but a space are concatenated and printed on a single line as a single string. Okay, very nice. What we can also do is we can actually multiply strings by a certain number. So let's say we want to GetString five, which is Mordor. We can actually multiply it, let's say by three. And when we run this code, you'll see that Mordor is printed out three times. We can multiply this by 40. Oops. We can multiply this by 40, run the code and you'll see that we have 14 Mordor. For Legolas to deal with, Let's keep it at four. Well, we can also go ahead and do this so forth. So I mean string times 4 plus 6. And before we run this code, I just want you to tell me what sort of output we are going to get when we run this code. So let's run it. And obviously we get an error in here. Why is that? Because this is a type error. We've already been through this. We cannot concatenate a string with an antigen. And it already gives us this warning right here, and you can see it over 6 or you can look the upper right corner, we have a warning and it's expected a string, but instead it got an integer. So how can we fix this? I'm going to give you just a little mini challenge. I don't have any slides for it, but how can we actually fix this problem in here without removing the 4 plus 6? Well, we can actually wrap this around a parentheses. And now the presidency of gold, we'll start off by adding 4 and 6, giving us ten, and then multiplying it by the string five. So when we run the code, you can see that Mordor is printed out 10 times. Very nice. We can also do something different. We can remove this and actually make six in another string. So now when we run the code, you can see that we get for more doors and A6 at the end. Very nice. You can also move the six right here to the beginning. Remove this plus in here, and then concatenated with the string five. Now, what do you think we will get right here when we run the code? Which will we get? Well, we get six Mordor printed 4 times 0 or well we get six. And then four more doors printed out. So think about the answer. Think about presidency and which operators will work first. So if we run the code now, you'll see that we get six and then four models because we, first of all start of by adding the model. So we have four models and then we add a sixth to the end of it. We can change that. We can add a parentheses around six and string five. Run the code and we get six Mordor six Mordor, six Mordor 6 model. Now, one more thing that is very useful when it comes to strings is we can actually check if a certain or certain characters or inside of this string. What do I mean? For example, I can write print and I can choose OR, and I can check, is all in string five, so is or inside of Mordor. And this should, should return true. For example, is OR, but with a capital O. Oops, and string five. And I'll let you guess what the answer to this will be. Should return. And I'll let you guess what the answer should be. We're going to print door. Is it in string five? Is Doron. String five, I don't think the door is inside of Mordor, is not a Mordor. That's a Mordor. So it should return false. And finally, we are going to check if we have rain. Rain without a space, of course. And my name is Michael. So, so this should also, should return false. And I've written for us here in correctly so forth. So before I run this program, I just want to let you take a little bit of time to try to guess. Is the or with a capital O different or the same to an O with a lowercase o. So think about the answer. I'm going to run the code right now. And as you can see, we get true. So OR with a lowercase o is inside of Mordor, but when it comes to a uppercase O or is not present and model. And this is because strings in Python are case sensitive. So Door is also not answering five and rain also not in my name's Michael. So with that said, in the next video, we are going to learn how we can print numbers using string replacements. I'll see you in the next video. 20. Printing numbers: Welcome back, My favorite Python developers. In this video we are delving into a lot of things. We are going to be printing numbers using two different ways. And we'll also have a big challenge to different weights. So with that said, let's not waste any more time. This is one of the longer videos and let's get started. Oh, okay, so we've seen that we cannot concatenate an integer with a string on a single print. We can solve this by using replacement fields or converting an integer to a string. So let's go ahead and do that. First of all, we're going to create a new Python file and we're going to call it printing numbers. So printing numbers, first thing we're going to do is we'll create a number. So now as for number of rings and in numbers, or number of rings where three. And we are going to print in here. There. Okay, So there where we're going to add a plus in here in order to concatenate. But for we concatenate the number of rings, we're going to convert them to a string. So now the number of rings, which is an integer, is converted to a string and then it is concatenated with a another string. And in here rings for SSH forged by Sauron. So if we right-click and run printing numbers, you can see that there were three rings forged by solar. So STR allows us to convert a normal integer into a string and use it in here to concatenate it with a print. But this can be a little bit tedious because let's imagine we have maybe 20 integers that we want to convert to a string every single time. It can be very hard and very tedious. Luckily, Python has a, another very nice way of dealing with this. So let's say we want to print the same line here. So there were three rings forged, and let's remove the conversion in here. And instead of converting, we can actually use a replacement field. So the way we use a replacement field is these two squiggly brackets with a 0 inside of them. And when we get to the end, we write dot and use the format. So format. And in here we are going to give it Which integer we want to convert. So replacement fields do as they say, before we continue, let me just run the code and then I'll explain. So as you can see, there were three rings forged by sovereign. Replacement fields do as they say, they replace certain fields that we add at the end using format. Okay, great. So now let's use it on a bigger scale. So here we are going to use the replacement fields not only to replace integers but also to replace strings. So we're going to write print the where and the first replacement fields, which are squiggly brackets, rings made for the elves. Seven. For this one. I'm not going to say what they are at the end. We're going to, if you already know, this is going to be a very fun game for you, if you know what Lord of the Rings is. And instead of continuing on and going through this entire line, we can actually hit Enter in here and continue on a second line. And you can see that we, the IDE IntelliJ, adds a double quote in here and to double-quotes down here to continue. So then for the men. And in here we're going to type format. So what is the format? So there were, how many rings in total? There were 19 rings made, one for the ALF. So how many there were 340 Alfes? Then there were seven for the womb, for the dwarfs. So, dwarfs, I hope this is how you write dwarves. And how many follow the man, how many rings for the man? They gave ops, I'm in nine rings for the man. So as you can see, we can use replacement fields for variables, for integers directly and also for strings. So when we run this code, you can see that there were 19 rings made, 34, the elves, 74 the dwarves, and nine for the spacing here for the men. So usually we wouldn't use replacement fields for strings because we can obviously have already do that. But I just wanted to include this in here just to show you how this works. So what we can also do is use the elements inside of format multiple times in here. So for example, we can add this two times and three times. And if we run the code, we can see that we get three 19s before we stop. Very nice. So with that knowledge, with that last single small tip, it's time for a challenge. And what a challenge. Is the days in a month. So use replacement fields to print the number of days corresponding to the month. So I'll give you an example. We'll need to print January 31 days, February, February 28th, March 31, April 13, 31, June 30, and so on and so forth. You can print them like this on a single line or you can also try print them like this, which is much but, and you can even do both. So pause the video right now and go do this. Amazing, a little bit hard shell. Oh, welcome back. So how are we going to do this? First of all, we're going to write print. It's going to be January. And then we are going to use this replacement field in here. Then we are going to get February. We are going to use this replacement field. And finally, we are going to, oops, I meant March. And we are going to use this replacement filled in here. And I'll just speed up the video because you don't need to watch me type everything out. Okay. Welcome back. So as you can see, we've added January, February, and I hope we've added all the right replacement fields. So what we're going to do, we're going to write format the 0 and here will be the 28 because it represents the number of days for February. V1 in April in Zhuang enjoin in September all represent 30. And the last field, which is two, of course represents the 31. So if we run this code right now, you can see that January, February, March, April, May, June until December. Okay, Great. So I hope you did the challenge on a single line. It's very easy. Now let's try and make this, print this each month on a separate client. So we're going to duplicate it. And the way we do this is actually by going ahead and printing in here. Let me show you. This is a bit tricky. And this is used whenever we want to add some special kind of printing. We can add in here Two more double-quotes in the beginning and two more double-quotes at the end. And what this allows us to do as actually allows us to go ahead and add a space in here or without and removing the cow common. And as you can see, now, I'm going to do this for all of these. So whenever we are using these triple quotes around our string, we can actually print each one of them on a separate line. Now if we run the code, you'll see that we have January, February, and actually we need a bit of space in here to differentiate what's happening. As you can see, let me make this bigger. January, February, March, April, May, June, July, and so on and so forth. So the second part of the challenge was a bit hard. I know maybe you tried to use backslash n. I congratulate you for thinking outside the box. Maybe you tried to research and see how this works. But in any case, I hope you enjoy it and I'll see you in the next video. 21. Section 3 - First Steps In Python: Introduction to Blocks and statements: Hey, welcome back, My favorite Python developers. In this video, we are going to be learning about two blocks and statements. We will be learning about what indentations are, and we'll learn why Python is such a radical and very easy to read programming language. Was that said, let's not waste any more time and let's get started. Okay, so let me put my laser on and let's start. What are blocks of code? So like many programming language, python uses blocks of code. Python's design philosophy emphasises code readability. We've already talked about that. So Python uses indentation instead of brackets to the limit gold. So what do I mean by all of that? If you are experienced with different languages, blocks of code begin and end with brackets, such as these. So for example, if you have a for loop, every time you want to create a block of code, you need to delimited using these two brackets. And if you're not understanding what I'm talking about or you don't know what this for loop does, don't worry about it. We are going to get to that. What I want you to understand is that whenever we have blocks of code that we want to execute, such as this one, we delimit them using brackets in other languages. But in Python, because it emphasizes readability, you can see that for loops don't have brackets. Instead we use indentations and this allows us for, first of all, better readability. Second of all, it's much more beginner friendly. And even when working in a professional level, it's also much easier to understand and read. So let's stop talking about blocks of code and let's actually go ahead and start creating them. So back in here, back in our IDE, let's go ahead and create a new project. This is of course going to be the project SDK. It's going to be Python 3.9. We're going to hit Next, make sure the true nowhere the directory is. And we are going to call this one program flow control. Program. Flow control. Hit Finish and choose where would you like to open this project? Yes, and this window. Great. So now as you can see, we have a new project and the deep python projects. You can save it wherever you want. And let's go ahead and create a new Python file. A new Python file. And we're going to call this block underscore and underscore, or blocks. And statements. Hit Enter. And now we have a new file of Python to work. So now I'm going to create a for loop. I don't want you to panic and if you're not understanding what I'm writing for now, I just want to demonstrate how blocks of code work. So we're going to write for I in range. And we are going to give it a range from 1. To 16. And we are going to close off with these two points right here. Then we're going to print the eye, which is going from one to 16. And then we are going to print this little dash right here 20 times. So let me just run the code so you can see what is happening and make sure that you have these indentations right here. So now when we right-click and run blocks and code, you can see right here, let me just make this a little bit bigger. You can see that we print from one to 15 you, and every line we have this number I printed out and we have these little dashes right here, 20 times over every single time. Now what is happening in here, whereas the block of code, so you can see this for-loop. It goes through the eye in a range going from one to 16. So it prints out from 12 to 15 because as we've said in Python, the rule is up to but not including. And each line we print out the I and then we print out 20 dash, dashes. So now we're going to add another print, but now we are going to not indented. So in here we're going to print, Hey, I'm not in it. Let's run the code again. And you can see the statement here, Hey, I'm not indented, is only printed once at the end of our output. So what we can do here is, for example, let's go ahead and remove the indentation from print, from the dashes that we are printing. And the way we remove the indentation is by clicking shift up. If we run the code right now, see that we print out one through 15, but the dashes are only printed once because we don't have an indentation behind it anymore. And in order to add an indentation, we hit up. And if we indent the print, hi, hey, I'm not indented. Let's change it to, hey, I'm invented. Run the code. And you'll see that, hey, I'm indented is printed out every single time our loop, while loops. So I don't want you to worry about how this code works. We'll delve deep into four loops later on. But for now, I just want you to understand how indentations affect the way our code is being processed, what is inside of a statement and what is outside of it. So with that said, I have a small challenge for you. So print out a personal message. Use the code I've written for you to play around with it. Go wild, explore, and play around with the indentations, see how it affects your code. So take a couple of minutes. Explored indentations used, use Shift Tab and see how it all works inside of the loop that we've created. And you can also play around with the ranges right here from one to 16. Maybe you want to add 30, run the code and have, hey, I'm indented, printed out 29 bumps. So, but that said, I hope you enjoy it. In the next video, we are going to be teaching our program how to take decisions using if statements. That's it. I'll see you in the next one. 22. If Statements: Welcome back, My favorite Python developers. In this video, we are going to be learning about if conditions, maybe you already know how they work. Maybe you're new to programming, but we'll learn how we can create the conditions in Python language. So let's not waste any more time and let's get started. So we've already learned about inputs and displaying them on screen. And now we'll learn a powerful tool in all programming languages that will allow us to make decision based on user input. So let's start off. What is an if statement? What is the structure of an if statement? So we start off by writing f, and then we check for some condition. If that condition is true, then we will execute a code block inside of the statement. So if this condition is true, then we will execute the code right here and always remember the indentation. But what if the scope is not true? Well, we'll see what we can do about that. First of all, let's start off by checking out how this if condition works. So back in our code, Let's stay in here inside of the block statement, and let's just remove this for now. First of all, we're going to get an input which is going to be an H, and it's going to be an integer. So we're going to write input in here, and we're going to ask, Hey, Mr. Barter, how old are you? And then we are going to print the age just for now. So we are going to run the code. And hey, Mr. Potter, How are you? How old are you? Let's say 15, and we print out 15. Very good. Now the next thing we're going to do is we're going to create an if statement. And based on that statement, we are going to print out something different. So if we create an if in here, we're going to check if the age is greater than or equal to 17, then we are going to print out, welcome to the party. Harry. So now this if statement is going to check for a certain condition. And if this condition is true, then we are going to print this line right here. And what is the condition? When is the condition true? It's true whenever the age is greater than or equal to 70. So luxury. Let's run the program. And hey, Mr. Potter, How old are you? Let's say we are. 1919 is printed and welcome to the party. Harry. Very nice. Now what happens? Let's run the code again. And if we enter that C5. You can see that we print out five and we don't have anything printed out. That's because the age is actually less than 17. And for that reason we do not get anything printed up. So this is of course working. This tells us that the if-statement is working, but what if we want to print something in case the age is less than 17? That's why we have something called the else. And the else works if the, if condition is not true or the condition right here is not true, then we will execute whatever code is inside of this else statement. So let me show you what I mean by that back in our code. And here, we need to make sure that the indentation is on the same level as the IF. And you can see the if and the else are always limited, or we always finish this statement using these two columns right here, these two points right here, and in here, in case the age is less than 17 or less than 18, we are going to print, sorry, Mr. Potter. But cure, not old enough to even do magic outside the scope. So now if we hit Enter, of course you need to also mine the indentation and here. So we run the code and you'll see how old are you, Mr. Potter. So let's say we are 12. We hit Enter. You can see that, sorry, Mr. Potter, but you're not old enough to even do magic outside the scope. So as you can see, if this condition is not true. So when this condition, when the age is less than 18, then we get this condition as false and the else statement is executed. So let's try this again. Let's say we use the age 18. Welcome to the party, harry. If we use 17, welcome to the party, harry. If we use 16, then you can see, sorry, Mr. Potter, but you're not old enough. So another thing that I wanted to show you is that we can actually add multiple lines because these are blocks of code. So we can also add in here, front. Here is here, Here, have a want also. So now if we run the code and we write, let's say 19, we get Welcome to the party harry, here's a wand also, and you can also do this in the else statement. Now, take the time, understand what is happening. Understand the condition in here, understand the else, and when you are ready, it's time for a small challenge. So your challenge is to create your own IF statement. So create an if statement that checks. If that checks if age is less than 17, print something if the condition is true, create an else statement and print a different message in that case. Now the goal of this challenge is for you to convert our if statement right here that uses first of all, the less than 17 at the beginning. And based on that, you need to play around and change the position of the printed statement. So with that said, pause the video right now and go do the challenge. Okay, welcome back. So we are going to go ahead in here and we're going to print these asterisks, and we're going to print them third times. And below that we are going to check if the age is less than 17, then we are going to go ahead and print sorry, Mr. Potter, you are not old enough to even do magic outside of school. And then we are going to add an else statement. And in here we are going to use these prints right here. So we're going to paste them the way you copy as you hold Control C after selecting and then Control V. I'm sure you already know this, but just in case. So now we'll run the program. And let's go ahead and 15. And you can see that both statements, so these both if conditions, this condition right here and this condition right here are separated by these 30 Asterix and you can see that they give the same result even though we are checking for different conditions. So I wanted to show you this in order to help you understand that sometimes you can write a code differently and still have the same results. So let's try if we give an age that is over 18, that say 18187. So welcome to the party, harry, here have a want and you can see that the second statement is or has the same output. Great, so that done. And the next video, I'm going to show you what happens if we want to add another condition. We don't want to just have the H over 17. What if the age is over 100? Just like in here. What can we do about that? Well, that done. I hope you enjoyed the video and I'll see you in the next one. 23. Elif Statements : Welcome back, My favorite Python developers. In this video, we are going to be learning about L IFS. So whenever we have some different condition, maybe you want to check for something else. We are going to be using L IFS. So let's not waste any more time and let's get started. So sometimes you might have several conditions to test. So let's say we have this if statement and here we have some condition. If it's true, we execute the scope. But what happens if we want to check for a different kind of condition? Well, in that case we have the LF and this checks for some other condition. Maybe we want a specific age in order to determine. And if this condition is not true, if this condition is false, we then move on to the LF and we check if this condition is true, then we execute the code in here. But if this condition right here on the first if statement is true, then we will ignore this and we'll see how this works later on. But first let's go ahead and test out our new learned LF. So in here, after we check if the age is less than 17, we are going to create or write L, F and here, and the condition in here is going to check if the age is equal, equal. And this checks if this is exactly the same, this compares the H to 150, so equal, equal. Remember that not just a single equal, let me just put a bit of space. And in here we are going to print, sorry, Dumbledore, you're just too old. So if we type in h, that is, let's say 15. Okay. So we get sorry, Mr. Potter. If we type in 150, you'll see that we have sorry, Dumbledore, you're just too old. But if you notice, we didn't add this LFO up here. I mean, we didn't add the f up here in this statement. This is why we still print out the normal execution. And when we have the LF, we print out, sorry Dumbledore, you're just too old. Now, I've told you that if the first condition is true, then we are going to ignore the second condition. So let me show you how this works. Let's say we copy this LF and we add it in here. Mine the indentation. So shift up. We have the if and the LF always on the same line. Oops, sorry. So we have the if and elif and else always on the same indentation. If we run the code right now and we write 150, you'll see that even though we added an LLF, we still get the block of code that is under the first condition. And this is how the else or the if-statement work works. It starts off with the first condition, and that condition is true. We execute the code and we ignore everything under it. But in the second statement right here, we start off by checking if the age is less than 17, which is not. So it's this condition in here is false. We then move on to the LF. We check is the h equal to 150? Yes, it is. So we print out the statement right here. Okay, great, now it's time for a small challenge. So create your own LF statement. So check for h greater than a certain value and print a message in that case. So pause the video right now and go to the challenge. Okay, welcome back. So first of all, we're going to add an if condition in here. And we're going to check if age is greater than 600, then we are going to print out, you, oops, add to con, you must be nicholas flatMap. And we are not going to add it to the first if statement because we already know that this is not going to work because as soon as age is detected over 17 or equal to 17, then we will immediately print out the code block and we will not even check if the age is greater than 600. Now if we run the code, you'll see that FAR age is 609, then you must be nicholas Flood. Very nice. So just make sure you understand before we move on how the LF statement works for one, for two, make sure you understand how if statements with an if statement works. So if the first condition is true, we will ignore everything under it and this happens for everything else. With that said, I hope you enjoyed the video and the next one we will be learning about the debugger in IntelliJ idea. So I'll see you in the next one. 24. Using the Debugger in IntelliJ: Welcome back, my fellow Python developers. In this video, we are going to be using the debugger, a very powerful tool, especially when you are starting off with coding to understand everything that is going on. So with that said, let's not waste any more time. And then as you start, oh, okay, so let's run our debugger. The way we run the debugger, we simply right-click in here. And instead of RAM, we debug the blocks and statements. So as you can see right now, there is nothing that appears, but it's a bit different and that's because we haven't yet set up any breakpoints. But you can see that we have this debugger right here and a console. Now we can stop the program, we can pause the program. So let's stop it for now. And if you are on a Mac, you might have to install something called the siphon extension. It should pop up right here. The program functions normally whenever we run the debugger, but it stops at specific points that we determined by clicking right here between the line numbers and the code. So if I click next to the if, age, if condition right here, you can see that we add a breakpoint. So now when we right-click and we debug, the program starts off, let's say, Hey Mr. Potter, How old are you? So I'm going to give it an 18. Hit Enter and you can see the code stops right here on the breakpoint. So age is equal to 18. And as you can see, we have the debugger and the console, and the console hasn't yet printed out anything. So let's see what we have in here on the debugger. First of all, we have the step over and this will step through our code as we are moving in our debugger. We have the step into right here. We won't be using that too much. The Step Into My Code, it's basically similar. We will check these out later on, step up or step out. And we have this evaluate expression which is not very important right now. So we are going to mostly be using this step over. So now in here we are on this line and we are checking if the age is over 17. So let's hit the step over. And you can see right now that we actually stepped into this condition. So when we hit the step over again, this line of code will be executed. So we step over and you can see that the console has this tiny little blinking warning. This means that something has been printed out to the console and you can see that it's welcome to the party. Back in our debugger. If we step over one more time, this line of code will be executed. So again, back in our console, you'll see that here, have a want. And why did we skip all of these? Well, as I've told you, whenever one of the conditions or the first condition that is Matt on one of the if or else if statements, everything else is ignored. So now we move through all of these weak nor the if and the else. And the next code or the next line of code that should be executed is the printing of these asterisks. So now back in our debugger, we step over one more time and you will see in the console that we have printed the asterix. And now in here, we, when we step over again, this age will be ignored. So we go into the h is bigger than 600. So when we step over, it's also getting ignored. If the age is equal to 150, this will also be ignored. And finally, we will hit the else statement. So using the debugger is very helpful if you don't understand what is happening in a quote. But let me just make sure I emphasize this point. So let me finish off. And in our console you can see that everything is printed out. So the debugger isn't something that you use in order to understand your code. It's something that you use in order to understand how your code is working and where it's not entering and which conditions not being met. So this is not a crutch to use. This is a tool to help you enhance your coding capabilities because many people use debuggers as a crutch and this leads to bad coding. Okay, great, so now it's time for a challenge. So debug your code, That's the debugger through your code. So run the code again, give it an input, and then check, make sure you understand how breakpoints and debugging works. So in this scenario, I recommend that you put a breakpoint on the second if statement and try to play around with the values, see how everything works. They got time understandable. Debugger works. It's very important for you later on with that done, I hope you enjoyed the video and the next one we are going to delve deeper into if elif and else statement. So I'll see you there. 25. Deeper Into Conditional Statements: Welcome back, My favorite Python developers. In this video, we are going to be delving deeper into ifs and else ifs by creating a fun guessing game for Mr. Weasley. So let's not waste any more time and let's get started. Okay, so to better understand how conditional statements work, we are going to be creating a game. And it will be a guessing game where we'll try to guess Nicolaas for animals h. So let's go ahead and create a new Python file. We're going to call this one Nicholas lamellae. H. Hit Enter, and before I continue one out, I'm going to issue you the challenge right now and you'll know why. So create your own guessing game. So create your own guessing game and it doesn't have to be the same as mine. This will make, make the learning process much more fun for you. And especially if you have no idea who Harry Potter is, because this is Nicholas flammable. If you know him, you know, if you don't, I recommend to think about your own guessing game. So back in our code, that's double-click on the tab. And let's first of all go. We're going to create a variable, an integer variable that tells us the actual age. So the actual age is equal to 665. Now we're going to print out what is familes age. We easily can, we are going to create a variable that will take in the integer input. And this variable is of course being called guess. So let's see what can we fix. Okay, so now if we run the code, nope, run this code. So what is females age? I don't know, 48 maybe. Okay, so now we have the guess taking the input 48. Now what we're going to do is we're going to check whether this guess is higher or lower than the actual age. So we are going to create a condition in here that will check if guess is smaller than the actual age we are going to print out. Please run guess higher. So please Ron, guess higher. And LF. The guess is greater than the actual H, then we are going to print out, please, Mr. Weasley. Guess lower. So what happens in here? We start off by getting an input. We are putting this input inside of the guess variable. And then we are going to create a conditioning here that checks if the guess is less than the actual age. We will ask Chrome to try and guess higher. If the guess is greater than the age, we're going to try and ask him through easily for a lower guess. Let's see if that's working correctly. So we run the code, Mr. Weasley. So let's see if we had 20. Please run. Guess higher. Let's try this again. Let's say we choose 900, please, Mr. Easily guess lower. Okay, great. So the code is working. Everything is great. I hope you, are. You thought about your own game. It can be the price of a car or I don't know anything that your heart wants. In the next video, we are going to use our debugger on this code and see how it's working. Well, that said, I hope you enjoy it and I'll see you in the next one. 26. Debugging if, elif and else: Okay, so before we start debugging, I just wanted to add an else in here that I forgot to do previously. And we're going to simply print out, you guessed correctly. Ten points for griffin door. Okay, great, so now we have our else statement. We can test it out if we guessed correctly. So 665, you guessed, you guessed correctly. Ten points for Gryffindor or K. Great. Now let's start debugging. So first thing we're going to do is we're going to add a breakpoint right here on the first if statement, right-click and start debugging. And now let's go ahead and try add a value. And we are trying to get the guest to be greater than the normal H. So let's see if we get guess 800. You'll see that the code start, starts off by checking the first condition. And this is important to understand. First of all, we check if the guess is lower. If it's not, before I continue, think about what will happen when we had the step over. So when we click on Step Over, you'll see that we go to the next LF condition. Now again, before we step over, what do you think will happen? Well, because guess is greater than the actual age at 800. And you can actually see right here on the code, you can see that we have the actual age and the guests that we've added, which is very helpful to look at all. You can also see them right here as the variables. So we are going to step over one more time and actually step into the second LF because the condition on here is true. When we step again, something is printed out to the console and the process has finished. Okay, great. Now let's go ahead and try to guess correctly. So oh, I'm into I meant to debug your stop and run. So debugging 665 had Enter, you will see is the gas smaller than the actual age or less than the actual age? Nope. So we're going to go to the LF. Is it greater? Nope, then we're going to immediately go through the cells and you can see that nothing, nothing is being processed in here. We simply jump right into the printing step over and that's it. We are finished. So there are no challenges right now. So your own challenges to play around with the debugger. Make sure you understand how it's stepping over and how things are being evaluated at each step. With that said, I hope you enjoyed the small little video and I'll see you in the next one where we will be improving our game. 27. Adding a Second Guess: Welcome back, My favorite Python developers. In this video, we are going to give a second chance to Ron Weasley to get the correct answer. So we're going to add a, another input and another if condition with its own else statement. So let's not waste any more time. And of course and let's get started. Okay. So it's time to give Mr. Weasley a another chance. Let's remove the breakpoint from here and let's go ahead and add a second chance. So what we're going to do is after we get the first guess, we check if the guess is lower than the actual age, will then print, please wrong guess higher. We are going to get a second guess, which is going to be equal to an integer, which is an input, where the input is an integer. We need to make sure of that. And then we're going to check again if the guest this time is actually equal to the actual age. If it is, we are going to print well done, Mr. or let's say Well done. Run ten points for correct. Is that how you write griffin door? Open door, and a couple of exclamation marks. Let's hit Enter. And in here, again, if we tried to guess and the guess is higher than the actual age, then we'll ask Mr. Weasley to get slower. And then we are going to give him the same output except for we are going to change this from Ron to Mr. Weasley, so we know where we got our second chance in here. So while you're writing the SQL code, make sure that you get all the indentations right? So this if condition in here that checks if the guess is equal to the actual age should be on the same level of indentation as all the other code inside of this code block. And another thing that I want to point out too, is the use of a single equal versus the use of 2 equals. And we use a single equal in order to assign a value to the variable guess. And we use the 20 equals right here. Whenever we want to compare if the values are equal. So let's run the code and test this out. So what is females age, let's say 50. So wrong, please guess higher. Let's try 665 and well done wrong. Ten points for griffin door. Let's try to get to this condition right here. The second one. So we're going to run our code again. We are going we are going to say hit 900, please. Mr. Vsd gets slower, 665. Well done, Mr. Weasley. So 10 for griffin door. So we got the Mr. Weasley part and we got the wrong bought. Another thing. I'm going to change this from ten to 20 because Ron gets it on the first try. And I forgot to add an n in both cases of griffin door. Very nice. Now as you can see, if we play the game again, Let's say we enter 500. Please run gets higher, so let's enter 30. What do you think will happen? Well, nothing. And that's because we haven't added an else statement for our Fs and it's part of your challenge. So your challenge is to add an else statement. So add an else statement to our new if statements inside of our if statements, and then make sure you have the right indentation. This is very important and each else should have its own unique texts in order for us to differentiate between them. So in order for us to know which else condition we've entered. So we'll differentiate that using the name Ron and Mr. Weasley or whatever game you have created yourself. So pause the video right now and go do the challenge. Okay, welcome back. So first of all, in here we are simply going to add an else and we're going to print Wrong again, R1. And another else in here that's going to be print Wrong. Again, Mr. Weasley. So let's run this code. And whenever you do a challenge, I hope you're making sure that it actually works by running the code. So we're going to try 300. Guess higher, 600, wrong again, I mean wrong again, RON. So we get caught in here. Very good. Let's try to guess higher. So 800, wrong, 400, MR. with the ramp again, Mr. reasoning. Okay. Very nice. So I hope you did the challenge correctly. And the next video we are going to delve deeper into conditional operators. So we'll understand what the equal, equal sign is. More understand the greater than, greater than or equal and other very useful operators. Until then, I'll see you in the next one. 28. Testing Operators: Welcome back, My favorite Python developers. In this video, we are going to be rewriting our entire code and making it much more elegant and yet have the same correct functionality. So let's not waste any more time and let's get started. Okay, so let's talk about a couple of conditional operators. Some we've seen, some we haven't yet, so let's check them out. So first of all, we've already seen this symbol. It's less than and no need to explain anything. The less than or equal to. So we use the twin when we wanted to get the age of Harry Potter. And we checked if it's less than or equal to, or greater than or equal to 17. So this includes 17 whenever we want to compare it, when we don't have the equal sign, that means we don't want to include the number. So this is very basic. We have the equal to, we've already covered this. So this whenever we want to compare two values and make sure that they are the exact same. And finally, we have the not equal to, and this is the first time we've seen it. So it's an exclamation mark with an equal. This means the complete opposite of equal to. So let's say we want to compare the, the guests that we got and the actual age. If we want to say whenever the guess is not equal to the actual age. So whenever we guess wrong, the condition will be true. And if it's a bit confusing, let us use this not equal to in our code in order to make it better. So back in our code. And here you can see that we have written a code and the program is working and that's fine. But it's a very bad habit whenever we have redundant code. So whenever we need to get an input and gets it, and then create an else statement in here. That's okay, That's fine. But when we need to do it, again, That's when you know that you have a slight program, I'm slight problem in your programming. So let's try and fix this. First of all, let's go up here. And let's just simply comment all of this out and rewrite our code. So we comment out using control and the forward slash. So we can even add in here. This was the old way of doing things. And now let's go ahead and start creating a new code in here. You can delete it even if you want. So reformat, what do we need? Oh, okay, so no worries about that. So in here we are going to start off by checking if the guess is not equal to the actual h. Whenever we tried to guess, we are going to then check. If the guess is less than the actual age. Then we're going to print out. Please Ron, guess higher. Else, this means if the guess was greater than the actual age, we are going to print out, please. Mr. Weasley. Guess. Load. Great. So now we start off by checking if the guess is not equal to the actual H, That means that we've guessed incorrectly. We are going to then check if the guess is less than the actual age, will ask ground to guess higher. Else, if it's greater than the actual age, we're going to ask Mr. Weasley to guess lower. And finally, if we actually have the guessed correctly, we are going to print out the same thing that we printed out in here. So you guessed correctly 20 points for Gryffindor and mind the indentation, of course. So let's try this code out. So we hit Play or we run the code. What is flamingos? H, Let's try 200 and you can see, please run gets higher. Let's try this again. So let's say 999 must please, Mr. Weasley, guess lower. So as you can see already, our code is much more elegant and yet has the same functionality as the previous one. But the only problem still here is that we don't get the chance to try another time. And that's part of your challenge. So your challenge is going to get a second input. So first thing you'll need to do is to write the code that will allow the user to input a second guess. So you'll need to get an input. Then you'll need to check if that guess was correct. And if it's not, you'll need to print a message based on the results. So you need to first of all, get a second input. Check if that second input, that second guess was equal to the actual age. You'll need to print based on that. And if not, you'll also need to print something out. So this is a bit of a harder challenge maybe for some of you because we are adding a lot of things together, but I'm sure if you give it a little bit of concentration, you can do it. Pause the video right now and go do the challenge. Oh, okay. Welcome back. How did you get on with that? I hope the challenge wasn't too difficult. So in here, first of all, we said we are going to get a second input. So it's going to be int input. Then we are going to check if our new guess is equal to the actual H. If it is, we are going to print. Well-done Mr. Weasley, 10 points for reference door. And okay. So Gryffindor with a Y, apparently, then we are going to add an else in case our guess was wrong, are going to print out wrong again. Mr. Weasley. Great. So with that done, let's go ahead and test our code out. So what is flamingos H, Let's say it was 200 and wrong. Please guess higher. We're going to check 665. Well-done mysteries, the 10 points from Gryffindor or for Gryffindor, that's tried to get it wrong. So 5 thousand please guess lower 666747 and mature wrong again, Mr. Weasley. So as you can see, this code, let me just make this smaller. You can see the difference between this code where we have a lot of redundant code and it takes us about from 2003 to 40, so around 17 lines of code compared to this really elegant code which is from six to 19. So around 13 lines of code, much more elegant, less redundant, and has the same functionality. So I hope you enjoyed this video. And the next one, we are going to write this entire condition in a totally different way. So even though it's much more elegant, we can even make it better. With that said, I'll see you in the next one. 29. If In A Different Way: Welcome back, My favorite Python developers. In this video, we are going to be rewriting our if condition. We are going to keep it mostly the same, but what we're going to do is issue you a challenge. So my starting off with a challenge but don't worry about it. It's not that hard. So your challenge is, what if the user gets it right? So rewrite the code to check if the user guesses or the user's guess was right the first time. If guess is equal to the actual age and then continue on. So you don't need to recreate everything. You can use the code that we already have. You just need to make a couple of tweaks. And so pause the video right now and go do the challenge. Okay, welcome back. So this is actually super, super simple. So we're going to remove the not equals and make it equal. And then what we're going to do is we're going to take this code in here and we're going to move it up. So the way we move it up is we hold down Shift and Alt, and we move it up to this position. And then we'll take this code and here, and we'll move it down under the US, and that's it. So I hope you didn't try to rewrite the entire code. And let's play or as our console. So what is flamingos? Age 15, please get sire 66, 5, well done. Ten points. Let's try again. Eight gets lower, 45, wrong again. Let's try this 1665. Okay, great. So as you can see, our code works the same. And this video was just to demonstrate that sometimes two different ways of writing code can lead to the same result. It depends on what you like and your coding preference. And sometimes you actually need to write in a certain way. So with that done, I hope you enjoy it. I hope you tried your best and the challenge, and I'll see you on the next one. 30. Complex Expressions using and, or : Welcome back, My favorite Python developers. In this video, we are going to be learning about complex expressions using AND, and, OR. And complex expressions are actually very easy. We'll also going to learn about truth tables. So let's not waste any more time and let's get started. So far we've only done very simple conditions. What if you want, for example, to test if a number is between two values? So in order to do that, let's go ahead and create a new Python file. And we're going to call this one complex conditions. Complex underscore conditions. Hit Enter, and let's start off. So now we're going to create a program that takes input from the user who is playing some kind of game on PC. That the input will be the temperature of the GPU or the graphics card. And if the temperature is between 20 and 70 degrees, that means it's working good. Outside the range of that the GPU is no longer working correctly. So if you are a PC gamer, you know what I'm talking about? Anyways, let's start off. First of all, we're going to get the input. So it's, let's call this variable term picture. And it's going to be equal, of course it's going to be an integer. It's going to have an input. And let's write how hot is your GPU. So now the user of our program or the player of the PC gives us the temperature. So we want the temperature to be, as I've said, between 20 and 70. So we can write temperature is greater than or equal to 20, and the temperature also should be less than or equal to 70. And if this entire statement is true, then we are going to print Great Khan, new, playing your game at 60 FPS. And Else print, oops, sorry, I can't I can try it. Can't play with an exclamation mark. Okay, so what happens in here and what is this end? Well basically and explains itself. We first of all check if the temperature is greater than 20. If it is, then we check if the temperature is less than 70. So if both conditions in here are true, then this entire statement is true, then we can go ahead and great, continue playing the game. If one of them is false, that means we cannot play our game and we print out, oops, sorry. So let's test this out. So we run our program. Of course, I forgot to run the complex condition. So how hot, how hot is your GPU runs again? So how hot is your GPU? Let's say it's 50. Great, continue on playing. Let's try ten. Sorry, can play. Let's try 100. Oops, sorry, can't play. So this is a complex expression and it's called a complex expression because it's made up of two simple expression. Either one of those expression can be evaluated to true, but the whole expression must be true in order to have this condition work. So how do we know whenever this one turns up true? So there is something called the truth table and it's an end truth table. So if we have two conditions, two simple conditions that are true, then we evaluate to true. If we have one condition that is true and another one that is false, you can see that we evaluate to false. If we have a false and a true, we get a false. And if both of them are false, then we get, of course false. Then we have another table of truth that we'll see later on that we are going to use in the next video. And that's an all truth table. So true and true or true. True or true is true. False or true is equal to true, false or false is false and true or false is false. So this is the, and the truth table. This is the OR truth table. Now for now we'll just leave it at that. Just remember that we have an AND, and an OR. Let me go back into our code. And you can see if we hover over this, we have this squiggly line. And if we right-click on it or just hover over, you can see that it's telling us, or intelligent the ID is selling us, simplify chained comparison. So what does that mean? Well, we're going to see in the next video until then, I'll see you later. 31. Simplify Chained Comparison: Welcome back, My favorite Python developers. In this video, we are going to be learning about simplified expressions. So we've changed the expression in here for just a little bit. We then tried to change it into an OR and we learned a very important rule whenever using complex expressions that have OR, and, AND. So let's not waste any more time and let's get started. Okay, So what was intelligent trying to tell us when it says simplify chain comparisons? Well, let's right-click and see what happens in here. So you can see that show Context Action, click on it. And you can see that we can simplify chained comparison. Let's click on it and see what happens. Okay, So as you saw, we have a change in the way our syntax as written. This is still the same expression, it's just written in a different way. Now, I recommend using this feature very sparingly and only when you, you're not sure what else can you write because sometimes can write a different type or different style from your own coding. So I just recommend using it very sparingly. But let's try and see if Intel J ruined our program or not. So how hot is your PC? 50, great, continue playing. Then. Oops. And 550 one. Oops, Okay, great. So now that we can obviously see the program is working correctly using end, let me just press on the Control Z and turn it back to how it was because I have a challenge for you and your channel's going to use an or. So, change the conditions to use or instead of end. And let me just take you back to the truth table so you can see how it looks. So this is an all truth table. So pause the video right now and change the end to an O. O K. Welcome back. How did you get on with that? Let's go ahead and fix this right here. So whenever we are using an order, let me just go back. Let me look at the truth table whenever we are using an or, if we have just one condition to be true or the other one is false or true, we get true. So let's try to apply that in here. So first thing we're going to do is we're going to check if the temperature is less than 20. What is this? So if the temperature is less than 20 or the temperature is greater than 70, then we are going to print out, oops, oops, that was my mistake. So we are going to hold down Shift Alt and move it up and shift off and move this down. So if the temperature is less than 20. Or the temperature is greater than 70, then we can't play. So let's hit Play. And let's see if we enter 40. Great, continue on playing. If we enter 80, oops, can't play. And if we have a temperature of ten, oops, can't play. So as you can see, we've converted this end complex expression into an or complex expression. Both give the same result and you can use which ever you want based on what you want out of your code. But there is one thing to keep in mind when using or end at. Python stops checking the rest of the end conditions, F1 is found to be false. So what do I mean by that? Let me just duplicate this line in here and let me just move it down just for the sake of PRB further, let's see, let's make this a comment. So as you can see right here, let me move this back. If we have an end and here the Intel J or Python, that's called Python because it's, Python's language starts checking for several end condition and we can have multiple and conditions and here, so Python starts checking this one is, it's true, it continues to the next one. If this one is true, it continues to the next one and makes sure all of them are true. If we start off by having this one true, then this one false, then Python no longer continues checking for other simple conditions because when one of them is false, then that means the entire condition is false. And that's because if we look back at our truth table right here. So the end truth table, you can see that if one is false, then the entire result is false. And the same as for the truth table. So back in here, back in our code, let me duplicate this again and commented out. So if we have a another or in here, and let's say the Python starts checking. So if this one is, let's say false, we continue. If this one is also false, we continue until we find that all of them are false. But if we come across a single one that is true, then Python stops checking the rest. And that's also because of the OR truth table. As you can see, if one of the condition is true, then the entire complex expression is true. So I hope you understood what I mean in the next video, we are going to be looking into Boolean values. And by the way, if at this point of course you're enjoying the course and you're like me as an instructor, I would appreciate it if you took just a couple of seconds to leave me a review, I would appreciate it a lot. It helps me out a lot. Thank you so much. I'll see you in the next video. 32. Boolean Values (True and False): Welcome back, my favorite parts and developers. In this video, we are going to be delving deeper into Boolean values, true or false and how they work with AND, and OR. So. Let's not waste any more time and let's get started. Okay, so first thing we're going to do is we're going to delete these two hypothetical lines and we're going to actually create a real-world tests to see how and or multiple ends in complex expressions work. In order to do that, we are going to create a new Python file in here. And it's going to be called Boolean values. So Boolean under scroll values, hit Enter and double-click on the stirrup. And let's start off. So we're going to create a test to check if we are being attacked by Luke Skywalker, and I mean Anakin Skywalker or Darth Vader. But anyways, all we need to do is create a couple of characteristics. So let's first of all check if the hair is black. We're going to check for the height. And we're going to set it to 1.8. And we are also going to check if, if he has IV, so evil is set to true. Now what we're going to do in here is we're going to check for several characteristics at the same time. So if we have the hair is equal to blonde and the height is greater than 1.6, and he is not evil, then we're going to print out, you must be. And it can Skywalker and a king, an Else print out. That's Darth Vader. Run. Okay, great. So what happens in here is we're first of all checking if the hair is blonde and the height is greater than 1.6 and he is not evil, then we must know that this is Anakin Skywalker. Else, if he doesn't meet any of these conditions, then he must be Darth Vader. Now you might be thinking what does not evil mean? Well, in order to show you and make it much simpler, I'm simply going to print out in here, not evil. And this will print out which, what is the value of not evil? So if it's true, so if evil is true, not evil will be false. So let's go ahead and run this program, run Boolean values. So as you can see, because evil is true, this means that whenever we want to print out the value of not evil, it's false and it's Darth Vader wrong. Now why are we going to the else condition? Well, first of all, because the hair in here is. Must be blonde and we have the hair as black. The height is evaluated to true and not evil is evaluated to false. Well, let's go ahead and change the belonged. We run the program. And you can see that even though we changed one of the conditions because we are using ends and not evil, still false means it's still Darth Vader. So what we can do is we can actually go ahead and change this end to end or so before I run the program, I just want you to think about what will happen in here. So we run the program and you can see that even though not evil is still false, you must be Anakin Skywalker. And that's because we changed this end to end or so as we looked at the previous truth tables, we can see that whenever we have and if one of them is false, then the rest defaults to false. If we have an OR if one of them is true, that means we default to true. But the problem in here, even though this expression Makes sense, we are not, it's not very obvious how it's working. So are we evaluating the end first or are we evaluating or first? Or are we just looking at it as a whole? Well, don't worry about that. That's why we have something called the expressions. So go into Google, type N operator precedence and Python. You should get this docs dot python.org. This is the most important documentations that you can fight for. Python, open up the link in here and do a quick search. So we are going to find the 6.17. Go down. Where is it? So in here you should find the operator precedence. And if you look right here, if you read a bit, the following table summarizes the operator precedence and Python from lowest these biding to the highest. So we start off, this will be the lowest and then we move down. And in here you can find multiple things such as the division and the multiplication and the addition. So this is the lowest, goes to the highest. You can see in here that the multiplication and the division rank higher or have a higher precedence than the addition and subtraction. And we can also find in here the OR and the end. And you can see that end has a higher precedence. So what's happening in our code in here is that the end is getting evaluated before the or. So. With that knowledge, with this stable available to you, make sure to find it. You have it in front of you. It's time for a small challenge. And your challenge is going to be to use parentheses. And why will you use them? Well, you're going to use parentheses to indicate how the expression is interpreted. Test your code to make sure you got it right. So you'll need to put parentheses just like we did previously when we were testing the operators on the addition and subtraction and division and so on. You need to put parentheses on our example here and indicate how the expression is being interpreted with that said, pause the video right now and go do the channel. Okay, welcome back. So as we've said, the end operator is interpreted first. So if we put parentheses in here, this is how the expression is being interpreted. So first of all, we are checking the hair if it's blonde, and then we are checking the height. If it's greater than 1.6, we evaluate this expression. And then we use this whenever we get this expression. So we get, for example, true or false. We then test it with the OR and check if he's not evil or evil. So this was a video just to show you a little bit how things are working together when we have multiple ends, multiple ors, and also how not evil or how we change the expression, how we check for something that is not how we reverse a certain characteristic, a certain Boolean value. Well done, I hope you enjoy it. And the next video we are going to be testing a truth values. I'll see you there. 33. Truth Value Testing: Welcome back, My favorite Python developers. And this video we are going to be taking a different look at truth values such as true and false. And we'll see how these expression can be evaluated with that said, let's not waste any more time and let's get started. Oh, so booleans can be defined using something other than just true and false. Let me show you what I mean. So of course we go to our different Google. We write truth values, Python and Python.org just so we can get the website, open up the docs dot python. And in here you can see the built-in types and you can see truth value testing. And this is any object can be tested for truth values to use an F4 while condition. We know what if is, we'll see what that is later on. And what's important in here are these three lines. So constants defined to be false can be none and false. We can use 0 in any numeric types. So for example, if we have an integer or a float, or a imaginary number, and so on and so forth. And whenever we also have sequences, don't worry about sequences for now, we'll learn them later on. So let us go ahead and play around with these things and our code. We are going to create a new Python file in here. And it's going to be called the Truth underscore values. So a new, brand, new Python file. So what we're going to do in here is we're going to test the numeric. So let's say for example, if 0 we are going to print out. This is true. Else we're going to print out this is false. And already you can see that there is a small warning in here, but let's just run it for the sake of running it. So we get this is false. So what's happening in here as 0 is being evaluated to false, that means that this condition is false. This means that the else is triggered and we print out This is false. Now what does the warning in here? If we hover over it, we can see that this code is unreachable. And why is it unreachable? Well, because we are using 0 which will never evaluate to true. So this code is on reachable. Okay, great. Let's go ahead and comment this out and let's test something else out. So in here we're going to get an input which is going to be the name. And it's going to be equal to an input. And we're going to ask it, what is your name? And then we are going to check. The name is just there. We're going to print hey, the format name. And else, if we don't have a name, we're going to print who are you? So what happens in here is that if we have a name, so if the name is different than none, then we are going to print out hey, there with the name. Else, we are simply going to print who are you? So let's run the program. Let's see what is your name? Michael. Hey, Michael, let's run this again. What is your name? If we simply hit Enter, you can see that it asks us who argue. And if we try to print the name and here we run the code, what is your name we had entered. You can see that because it's empty, that means that this name is an empty string. That means that this expression or this condition evaluates to false and we don't enter in here. Now I'm going to issue you a small challenge in order to make sure that you're understanding what is happening in here. So checking for an empty string. So change is, change this from a simple condition to check if the name variable is actually empty. So instead of simply writing name, you'll need to check if the string is empty. If you think you know how you can do this, then pause the video right now and go do the challenge. If not, I'm going to give you a small hint. So the way you check if a string is empty is by checking if it's equal to, well, simply these two quotes right here. And you can also see that. And our documentation right here, even though they are not using the double-quotes, this is for the strings. You can use double-quotes. And these sequences, as I've said, will look into later on with that said, let me go back, pause the video right now and go do the challenge. Okay, welcome back. So I'm going to comment this out and I'm going to go ahead and check if the name is not equal to. So this is something that I didn't tell you. You need to make sure that you did this. So if the name is not equal to an empty string, then we are going to print out hey there with the name in it. So let's run the code. What is your name? Michael. So I'm still printing out Michael. You remove this, we don't need it. Let's run this again. What is your name? Hit Enter, who argue? So now this is how the expression is actually being evaluated. If name, that means if there is something in there, we move inside of here. This is a much simpler version than using this code. So with that done, I hope you enjoyed it. In the next video, we are going to be looking at n and not n. 34. Section 4 - Loops In Python: Introduction To for loops: Welcome back, My favorite Python developers. In this video, we are going to learn about for loops. Now we've already seen for loops before, and I've told you that we are going to learn them later on. So let's not waste any more time and let's delve into four groups. Okay, So what is a for loop? What are loops? Loops can execute a block of code a number of times, and we can determine the number of times that we want to execute that code. All we can give it a certain value. We'll predetermined the number of times we execute that code. We'll see that, we'll see all of this, how it works later on. Loops are handy if you want to run the same code over and over again, each time with a different value. And we'll see in an example in just a bit. And this is the structure of a for loop. So as I've said, as we've said multiple times, Python is based on the ease of readability. So it has no brackets and it also works just as if condition where we have indentation indicating where the blocks of code begin and end. So we have the four, we start off by writing for. In here we determined the number of times we want to loop through. And then the code right here that does some stuff and the code to execute and so on. So was that explained with the small short explanation? Let's go ahead and create an example so we can better understand for-loops. So in here, back in our code, and this is a very handy tool in intelligence that gives you a tip every time I recommend you read them. Anyways, we are going to create a new project. And this project is going to be called loops in Python. Hit Finish and this window. And here we go, a new file. So I mean a new project. And now we're going to create a new Python file and here, and we're going to call it for underscore loops. Hit Enter, and now we are ready to go. So first thing I'm going to do is I'm going to create a message which is going to be a string and end the message I'm going to write, I'm learning python, correct? So the next thing we're going to do is we're going to create a for loop that we'll go over each character in our string and print it out. So we're going to create a fourth. We're going to create a variable in here that's called character. And we're going to search inside the message. And every time we get the character, we are going to print it out. So before I delve deeper into what's happening, let me just run the code so you can see what this does. So we run the code and you can see if we scroll up that I slash m. A space L, E, a, R. And I'm learning Python, so each character is being printed out. So what is happening in here? Well, first of all, we've created the message. Of course, you know that the string is a string of characters. So what we're doing is we are looping through each of these character, and at every point we are assigning the character in the string to the variable named character, and we are printing that out to our console. So in order to understand this better, we are going to go ahead and create a breakpoint right here on the for-loop. And I'm actually going to give you this challenge because you are already very proficient with debuggers. So use the debugger, setup the breakpoint on the for loop. I've already done that for you. Goes through your code and make sure you understand how this for loop iterates over the string message. So with that said, pause the video right now and use the debugger on your four. Okay, Welcome back. So let's go ahead and right-click in here and debug our for loop. So we start off and as you can see already, we have the message I am learning. And right now we are going to start to step over. So we get to the for loop. We step over and you can see right now that the card character gets assigned the latter. We are going to print it. So we step over and we can see that something has been printed to the console, which is I. Again, in the for loop, you can see that we are going to execute this line of code. And now the character, we'll take the second for the second character in the string. So again, we step over. Now we have this as a little slash and you can see the backslash in here to indicate that this is a special character. We've already learned how to use the backslash. So we step over again. Now it's an M, Now it's a space, now it's an L, E, a, R, and there we go. I'm learning Python. Okay, Great. So I hope you did the challenge. I hope you understand how this is working and let me just stop and run. Okay, Great, So I hope you understand how this for loop is working, how each character is going through the message. And you can actually see how we are iterating over multiple times this one block of code. Of course, we can add multiple lines and we need to make sure just as we do in the if condition that we indent our code that is supposed to be inside of the block. Well, that done, I hope you enjoyed. And in the next video we are going to be delving deeper into the debugging of our for loop so we can really understand it much better. I'll see you in the next. 35. Debugging a for loop: Welcome back, My favorite Python developers. In this video, we are going to take an old code where we were getting data coming in and we are going to make it much more dynamic by printing out all the separators, no matter the distance between each of our characters. So let's not waste any more time, and let's delve deeper into four. Okay, so let's go back to a previous project that we did in the Hello World project. And this was one of them where we tried to remove all the separators. Now let me just run this code. I run strings, you can see that we get the separators and the latter. But what happens if, for example, I put a two in here, a third, 23 in here, and let's say a 63 numbers in here. So if I run the code again, you can see that we have a very failed the program. Now thankfully, thankfully, we've learned something that can help us prove. So let's try to fix this using our program. To do that, let me copy this string of data right here. And let me put it back in our for loop right here. Because the previous one is very cluttered. And actually let me just shift Alt, move this down, and I'm going to comment all of this out and start fresh. So what do we want to do in here? Well, we want to print out all of our separators. First thing we're going to do is we're going to go ahead and create an empty string in here that's going to be called the separators. And not sure if that's how you write separators. Separator. So it needs an a in here. Okay, so separators, I'm not the best at spelling. Anyways, good thing we are using a computer and we're going to create a for loop. We're going to get the characters and the data coming in. And we're going to check if not characters dot as numeric. Then we are going to get the separators and we are going to add to it the characters. And finally, when we finish with our loop, we are going to print out our separators. So what is going on in here? First of all, let us see, this is our data that is coming in. This is our empty strings separator. And we are creating a for loop, just like we did in the previous video. What's happening in here, as you know, the, each character staking is replaced by the value inside of the string. So we start off by six, the comma 36 and so on. We are then checking inside of the for loop every time if the character is not numeric and if we hover over the numeric, you can see that it returns true if the string is a numeric string and false otherwise. So if it's something different than a number, than this returns. And because we are adding a knot in here, then every character in here that is not numeric is entering the for loop and we are adding this character to the separator using this plus equals. Now what does this mean? Well, it's a way for us to write the sentence. So separators plus the character. So what's happening here is we're taking our separators, which is here. We are adding to it what the separator already was plus the character. So every time we don't want to reset the separator string, we want to add to it what it already is plus the character. So an order to abbreviate this, we simply write plus equals. And finally, we are printing out and notice that the indentation in here is different. And also notice something because this is the first time that we have two blocks of code inside of each other. We have the first indentation for the F, and then we have a second level of indentation, I mean, for the for loop, and we have a second level of indentation 40. So this makes sure that this block of code is inside of the if statement, and this if statement is inside of this For Loop. Was that done? Let's go ahead and run this code. And you can see that now we are printing out all the different characters and we can add whatever character we want, how many numbers or letters we want. Let me just add a couple of numbers in here. And you can see that we can always run the code and get all of the separators. Now as a challenge that I haven't written, I want you to put a breakpoint somewhere in our code and run that, run the debugger and understand how this is working. Okay, so let me just put a breakpoint in here. Let's right-click and debug our code. So as you can see immediately we move through until we get to this line, we can see the console hasn't printed anything because we are, We didn't go out from our loop. So we are going to step over and you can see that the character right now is this little cup. We are going to step over again. The character will take a, another form which, which is three. So character is numeric, it is, but we are checking if it's not. So what's going to happen? And here we are going to skip over again. It's a six, It's a 645. And finally, I stepped over inhibit 2 first. But as you can see, when we had something that wasn't numeric, we had this front slash. We go into the separators. And you can see what separators is right now when, when I step over, and this is the magic of plus equals when I step over, you can see that now the separators which only had a common limit is taken and we add to it the character, not replace it with the character. We add to it, the front slash character, and so on and so forth. Let me just keep doing this until we finish with our console and we get the separators parented up. So I hope you understood how to score it is working. I hope you took the time to use the debugger. It doesn't matter if you put it out in a different place as long as you understood how this is working. And on a final note, I just wanted to make sure that true, no, if we add or comment out the separators and here, this is not going to work. We have to create a variable for an empty string that is called separators in order to use this plus equals The Don, I hope you enjoy it. And in the next video, we are going to use for loops over a range and not a predetermined value that inhibit. So I'll see you in the next video. 36. For loops over a Range: Welcome back, My favorite Python developers. In this video, we are going to create a for loop, but it's going to be over a certain range. And B are going to print each one of the values on a separate line. So let's not waste any more time and let's get started. So in Python we can actually iterate over a certain range, and we've already seen before. So let's go ahead and create a new Python file. And this one's going to be called FOR loop under score range. So let's double-click in here and we're going to create a for loop. So this for loop is going to have the eye and range. So I in range. And we are going to go from one until 30. And remember what we always say it's up to but not including. So we're going to print, and here I two dots and use a replacement field with the format right here of the eye. So what this will print, you'll see what this prints. But before we do that, think about what it will print. So we're going to run for loop range and you'll see that we print out I going from one until it gets to 29. And this is it, this is what is happening. The range goes from one until 30, but of course not including, as you can see in here. And every time we loop through, we get the eye and use the replacement field in here. And it's typically, it's tradition to use I whenever we are using for loops in sight of ranges. So I'm going to issue you a small challenge. So your challenge is to test the range. So play around with the ranges, experiment with various ranges and see what works and what doesn't. And I'll just give you a small hint right now. Try to test negative ranges and see what happens in there. I'm not going to go into, go into this in this challenge in this video because later on we are going, we have an entirely separate video for that. So with this video done, pause the video, play around with ranges and I'll see you in the next one. 37. Deeper into Ranges : Welcome back, My favorite Python developers. In this video, we are going to delve deeper into ranges. So you will see the way we can use ranges just like we do with slicing. And we'll also have a challenge where you are going to change something that we did previously and make it more efficient using two ranges. So let's not waste any more time and let's get started. So in the last video, I've issued a challenge to play around with the ranges, and I hope you tried to test everything up. So another cool thing about ranges is that you don't have to provide a start value. So if we write, let me, so if we write in here, for example, just 13 and run the code, you'll see that we start off from 0 and go all the way to 29. Because as I always say, it is up to but not including this as a very important to remember. Another thing that we can do is we can actually give a step. So for example, let's say we want to go from 0 to 30 or 29. We can add a step of two. So now when we run the code, you can see that we go 0, 2, 4, 6, 8, 10, and so on. So we can also provide a step to our range just like we do and we are slicing. Another thing that we can do, just like in slicing, we can go backwards. So we can go from 3200 with a minus2 step. So when we run the code, you'll see that we can go 30, 28, 26, and until we get to 2 because of course, the 0 is not included. So this is all that I wanted to show you. And before we go, I have a small challenge for you. If you go back to the program where we tested the temperature for our GPU, what I want you to do is I want you to use the range instead of checking for the temperature, the old fashion way. So use range instead of the operators to evaluate the condition on the temperature. So the hand in here is that you need to check if the temperature is in range. And use the range that you have. Remember, it's up to and not including. Pause the video right now and go do the challenge. Okay, welcome back. So in here we are going to use temperature. We're going to check if the temperature is in the range. And what is the range in here? If it's between 2071. And we'll need to change this up. So we're going to move the print up here and the print down here. And as you can see, there was a pass. Let me just show you again the space right here. We're going to get to that later on, but let me show you what this does right now. Whenever we have a f or an else and it's empty, intelligent idea immediately fills it up with this pass. This does nothing. It simply has added in here because you cannot leave an else or an empty. So we'll move this down. You can see that it disappears automatically. We right-click, run complex conditions. How hot is your PC? 50, great, continue on playing because 50 is between 2071. And again, why did we say 71? Because it's up to and not including. So if we type in 70, great, continue on playing. If we type 71. Oops, sorry, can't click. So this is the greatest, the biggest evidence of up to not including and why. It's very important. Because you can sometimes create very difficult problems and you're not sure what the problem was. Until then. I'll see you in the next video where we are going to learn about nested loops. So loops inside of loops. 38. Nested for loops : Welcome back, My favorite Python developers. In this video, we are going to learn what nested loops are. And you can see right here that we have a for loop and we have a second for loop. But because of the indentation, it means that it's inside of it. So let's not waste any more time and let's get started. Okay, so nested loops are loops that are inside of other loops, which means they are nested inside of other loops. So to create a nested loop or a very useful thing that looks can do is create calendars. So let's go ahead and create a calendar. And why a calendar? Well, because months have weeks and weeks have days and what we are going to focus on the weeks. So we're going to create a for loop with a weak in range, and we're just going to have four weeks for now. So it's going to be going from one to four or three. Then we are going to print out week with the number of the week, format. Week. So this is going to print on each line a week. And then we are going to nest a loop inside of it was the day. And the days range of course is going to go from one to eight because we have seven days and we are going to print out on each line the day. And we're going to use the a tab in here and the day with a replacement field where we are going to add the day. And finally, after each line, oops, sorry. And after each line printed, we are going to go ahead and print the star around certain time, I think is enough. So 30. Okay, great. So what is going to happen in here? First of all, we have the week going through a range going from one to four, so it's going to have three weeks. And each week that passes, we are going to print the number of the week. And then we are going to print out the day inside of it. So inside of each week we are going to print seven days on a line. And every, with every passing week, we are going to print these lines in order to differentiate between them. Now, think you need to keep in mind, and here is the indentation so you can see the four and the week or I mean the print and the second for loop are on the same indentation. We then have the sprint on a second degree annotation if you want for the second for loop. And finally, we have the print on the same level of indentation as the for-loop, the print and so on. And this indicates that we have this printing you through this for loop up here. So the sprint is part of the code block of this for loop. So right-click run calendar. And let's make this a bit bigger. So as you can see, we have week one, we use the t in order to indented day one, day two, day three, day 7, then week two, they want until they 7 and Week 3. From one until seven. So we can also use a debugger in here. And you can do this on your own. So you can use the debugger, debugger anywhere you want. And we can add a debugger in here, right-click and debug the calendar. So as you can see, we are at Week 1. We stepped through. We have the one and then we print, and then again we have the two, we print the three, we print A4, we print the A5, A6. And as you can see, the week is still one right here, you can see it. And then we step over, and when we get to seven, we step over that we print the 30 stars and then we go to week one. We move through it, we have week two. And right here you can see that the range starts again at the one, and so on and so forth. So I'm going to stop this for now. And now that you understand how nested loop works, there is another very useful thing that we can do with them, and that is a multiplication table. So create a new Python file called multiplication table and use nested loops to print out the multiplication table from one to nine. And this is how the multiplication table should look like. So you're going to start off by creating a loop that goes from one to I am to nine, and then a nested loop inside of it that goes from one to nine also. And then you are going to print all of that. Make sure to multiply them using print. So pause the video right now and go do the challenge. Welcome back. So first thing we're going to do is create a new Python file. So we're going to call this the multiplication table. And here we are going to create the first for loop. So it's going to be in the range going from one to ten. Then in here we are going to create a nested loop with G going in view range, also from one to 10. So this was a simple range to get. And then we are going to go ahead and print. We're going to use a replacement field. We're going to multiply it with the second replacement field, and it's going to be equal to a third replacement field. So what is the format in here? It's going to be I multiplied by j, and the result is going to be I times j. And finally, with each, let's say i, we are going to print out these little dashes in here just to have a bit of a change from stars will add a last line. We are going to right-click run multiplication table. And let's see. And as you can see, that smooth up 1 times 1 equals 1, 1 times 2 to 1 times 9, 2 times 9, 18, 3, 4, 5, 6, then and until we get to a nine. So I hope you did the challenge. I hope it wasn't too hard. I hope you understood how ranges works of the most important thing that you need to get as how j goes from one to 10 while I is still at one or two. And the other thing that you need to understand is the level of indentation. So that done in the next video, we are going to learn how we can continue inside of loops and we'll see what continue meats until then. I'll see you in the next. 39. Using continue in for loops : Welcome back, My favorite Python developers. In this video, we are going to be learning a little bit about lists, and we are going to be using continue and our code whenever we are looping through. So let's not waste any more time and let's get started. Okay, so in this video we are going to be using lists. We are not going to delve too deep into lists, but I thought a good overview is a nice idea. So what are lists in Python? Lists are a collection of objects of the same type. So they can be accessed using indexes just like we access characters and strings using indexes. And they have methods available to them to access so and search and modify them. So this is the typical structure of a list. Let's say we have a list of computer items, it has a name, computer underscore items, and it's equal to, we use these two square brackets. And in here we can add the keyboard mouse monitor and we can add as many as we'd like. Now. It doesn't have to be strings or it doesn't have to be a list of strings. It can be a list of numbers, 1, 2, 3, 400, 600. We'll see later on different examples. But for now let's stick with a list of strings. So back in our code and here, let's go ahead and create a new Python file. And it's going to be corps underscore dealership. Okay, great. So we'll open up in here. And now we are going to create a car list. And we are going to have different types of cars. So you can add whichever cards that you like. So we're going to have a BMW, a Honda, Ford, Ferrari Wagon, and an Aldi. Great. So now we have this list of cards and you can see that each one of these cars is a string and they are all part of the same list. Make sure that you add these square brackets on each side. Now what we want to do is we want to print out this course in a fun way. So we're going to use a for loop to loop through the items. So just like we do whenever we want to loop or get characters from a string, we can also use the same method in order to loop through the items inside of the car list. So we can write four core and the core list we are going to print out. I like driving my, and we're simply going to concatenate car. And here no need to use replacement fields for now, because this is a very simple printing. We're going to run local car dealership. And you can see that I like to drive my BMW, my Honda, my fourth, my Ferrari, especially my Ferrari, I wish, and my wagon and Audi. Okay, great. So now I'm going to issue you a small challenge. And don't worry, it's not a very hard challenge. There is nothing here that you don't know. You just need to use this list. So change the code to buy all the cores except for fourth. And I'm going to give you a small hint in here. So you'll need to create an if condition inside of the for loop and the rest is on you. So pause the video right now and go do the challenge. Okay, welcome back. So how are we going to do this? Well, the first and very simple method is, and here we are going to create an if condition. And if the car is different than forth and make sure the true intent, the print in here. So now if we right-click and run the code, you can see that I like to drive all my course except the fourth. Okay, great. So now we don't buy the fourth, but there is a different way of excluding an item from a list and that's why using continue. Now, I'm going to comment this for loop out because we are going to be creating a different one. And we're going to go ahead and create this for-loop in a car list for car and car list. And in here we are going to check if the car is equal to 4. Then we are going to continue. And then we are going to be printing out, I like driving my plus car and simply concatenate. So now if I right-click and hit run, you can see that we have the same output. I like driving my BMW, Honda, Volkswagen, and not the fourth. So what is happening in here in the code? First of all, I want you to pay attention to the indentation on the Continue and the indentation on the print. So the print is not part of the condition of the car equaling the fourth, as you can see, it's not being affected by the condition and yet we are not printing out the fourth. So what is the continue doing in here? Well, I'm going to, instead of explaining it with words, I'm going to use a debugger in order to show you what is happening. So we are going to set a breakpoint in here. We are going to right-click and debug car dealership. So back in our console, you can see that we don't have anything in our debugger. We at we are at BMW. So if the car is equal to Ford, No, it's not. It will continue to print. Great. Again, Honda nope, foot. So what will happen in here? We are going to enter into the if statement. So when we enter, you can see that we are at Continue and now pay very close attention to what will happen. We are going to skip over the print and immediately start the for loop again. So when we step over, you can see that we ignored print entirely and that is the role of continue. So what it does, it actually continues or the word continue, it actually skips everything else left in the loop and then starts again on a fresh start. So you can see that me just do this again, stop. And let's debug the code again. And you can see again BMW, Honda, Ford. And now when we hit the continue, we stop whatever else is left and the loop. And then again, we start with a fresh item in the list. So this is the use of the continue and actually continue can be entirely avoided because some languages don't even have. But maybe in the future you may come across it and you need to know what it actually does. So what that done in the next video, we will be learning something much more interesting and important, which is the break and the for loop. Until then, I'll see you in the next video. 40. Using break in for loops : Welcome back, My favorite Python developers. In this video, we are going to learn about the break and understand why it is so important to have it in our for loops. So let's not waste any more time and let's get started. Oh, okay. So Rubrik, if continue allows us to continue with the loop, break, breaks us out of the loop. So let's see how this works. So instead of continue, I am going to write break and we'll keep it at fourth and watch closely what is going to happen. So if we right-click and run the car dealership, we can see that the output on the console we get only riding or driving the BMW and driving the Honda. So we are skipping over the fairing and the Volkswagen and Audi. So what happens in here when we actually get to the fourth, we not only continue, we actually break out of the entire loop and stop going through it. And this is very good whenever we want to save memory when we are searching for a certain item in our list. So let's try this and tested in a manner that is actually beneficial to us. So let's go ahead and comment this for loop out. And let's create a another 1. First thing we're going to do is we'll create two variables. So the car to drive is going to be equal, let's say to the Ferrari. And we are also going to create a variable in here that is called the car index and this will be set to none. And why are we sending to non? Well, first of all, what is the core index? We want to search for a car and our core list. And we want to get the index at which it is present. So we want to find We're the Ferrari is present in our car list, so we need a variable for it. And because we cannot just create variables without setting them to anything, we need to set the current index two and not. Now let's continue on. We are going to create a for loop and we're going to have an index and here, and it's going to be an range. And what is the range that we want to search? Well, we want to search throughout the entire car list. Now, we can count each of the items and see how many there are. But what happens if, for example, we add another car? Should we go back in the range and change it? Of course, this is not a very viable solution. So what we can do is we can actually get the length of our entire list, and this is the length of the car, the car list. So what happens now is that we loop through the entire core list using this length guard list. And let me just demonstrate how to slugs. So let me just go ahead and print out the length of the core list. If we run the program, you can see that we have six cars. And if we add another color, let's say a Bentley. And now if we run the code again, notice that now the length becomes seven. So this is a very good way, a dynamic way of getting the length. So this is how we run, right, Bentley and waste. Let's go back to our example in here. So we have the index in range, and we are going to check if the core list at the index that we're searching in is equal to the card that we want to drive. Then we are going to make the variable that is core index equal to the index. And when we finish looping through and outside of our for loop, we are going to print out your a replacement field is in the replacement field with parking space. And the format in here is going to be, of course, the car to drive, which is our Ferrari, and the core index, but we are going to add a plus one to it. And why is that? Why are we adding a plus one? Well, because as we've learned whenever we are going through a sequence, it always starts off at 0. And we learned that when we were using strings. So if we, for example, wanted the BMW, we don't want the, we don't have a his zeros parking space, so we are going to add a plus one to it in order to accommodate for the 0 position. So every, so they will all be shifted one unit. So let's go ahead and run this program. And you can see that sure, Ferrari is in the fourth parking space. Now, let's go ahead and reread the scold, make sure that we understand everything that's going up. First of all, we get the car to drive, which is a Ferrari. Then we get the car index. We create the variable, we set it to none. Then we create a loop where we have the index go through the entire length of our sequence that we've created in here. Then what happens in the if condition as we are looping through, we take our core list and at every index we check if it is equal to the car to drive that we want. So as we used to do with when we were getting characters from our strings, we are also using this right here between the brackets on our car list. When we do find the card that we want to drive, we take this index and then we added to the car index. Now, what is the problem in here in the scope? I'm going to add a breakpoint in here, and I'm going to run the debugger. So currently we are at index 3. As you can see, we are at the Ferrari car to drive us. Erotic or index is none. We are at index three, so it's 0 for the BMW 14, the 100 to 443 on the Ferrari. So then we are going to step through. And as you can see, even though we already found the Ferrari, we are still moving through our loop. Now this, you might think it's not a huge problem, but what happens if we have, instead of seven chords in here, we have 10 thousand cars. In that case, it would take a lot more memory and this is where the break comes in. So we are going to add a break in here. And now if we run the code again, stop and return. You can see that we get your Ferrari is in the fourth parking space. Now as a mini challenge, I want you to put a breakpoint in here and debug your code and see what happens before i 2 0 case. So we are going to start debugging ion. And as you can see, we are at index three. We have the Ferrari. We step over, we get to the break and notice what happens now. So when we step over again, you'll notice that we are out of the loop and we are going to print out your Ferrari is in default parking space. So as you can see, we have saved a lot of memory. We didn't have to go through the Volkswagen, The OD, and the Bentley because we already found chord we are looking for. So this is the power of using a break. In the next video, we are going to be learning more about what this non is. So I'll see you there. 41. Why Use None : Welcome back, My favorite Python developers. In this video, we are going to be learning about the importance of using non and the importance of creating a variable and setting it to none. We are also going to learn how we can avoid certain errors in the case where we don't find our car in our search in the list. So let's not waste any more time and let's get started. Okay, so let's see what happens if we try to find a car to drive that is not in the list. So let's say we want a gamble and that's not going to write Lamborghini. So we're going to run the code. And as you can see that we have an error in here on lines 11. And because we are trying to type error and supported because we are trying to add two variables, a NoneType and an integer and y. Is this a non type? Well, because as we are moving through our list in here, we didn't find the Lamborghini inside of our catalyst. So the currIndex never took a value, it never became an integer. It remained a non. We are trying to add a plus one to it. So for now let's go ahead and remove the plus one, and let's try to comment out the car index and let's see what happens. So as you can see, there is no error. There is a warning though. Then we run the code again. As you can see, we have another error, a name error, and this name is the car index is not defined. So as you can see, first of all, we always need to define our variable as none. And then we need to make sure that this non is never OR never remains as it always needs to take a value. So how are we going to try to avoid it? Avoid this. What if someone actually wanted to search for a Lamborghini and we don't have It. Does he get an error? Of course not. There is a way to fix it and you are going to be the one that fixes it. So your challenge is going to check if not, not. So create a condition that checks if a car index is not none, print a message. If it isn't, and add an else statement with its own message being printed. So you need to create a condition that makes sure that the car index is not, not. With that information. Pause the video right now and go do the challenge. Okay, welcome back. So first thing we're going to do is we're going to add the color index uncommented. Then we are going to add a plus one and here. And when we finish looping through our code, we are going to create a condition in here. So if the car index is not none, then we are going to go ahead and print out our usual print. Else. We are going to say print, sorry. Couldn't find your dot format and the car to drive. So now if we let say have the Honda, we run the code. Your hand is on the second. Second. Well, maybe we should change this. Don't worry about that for now. And let's say we want a gamble. So we run the code and it tells us, sorry, couldn't find your lambda. So as you can see, we have avoided the problem. And now you understand why we need non, so desperately it represents nothing and it helps us avoid errors such as the ones that we've seen right now. So with that done, I hope you enjoy it. And in the next video, we are going to be looking at a wild loop, a different type of loop than before. So I'll see you then. 42. Section 4 - Loops In Python: Introduction To while loops: Welcome back, My favorite Python developers. In this video, we are going to be learning about another loop, which is called the while loop and the difference between it and a for loop. So let's not waste any more time and let's get started. Okay, so what is a while loop? And Python, so similar to for loops at executes a block of code a number of times. But instead of determining the number of times beforehand, we wait until a certain condition is met until we stop. So let me show you the structure of a while loop. So we create, we write actually while. A certain condition is true, we do stuff and execute some code. And until that condition becomes not true, then we stop the execution. Okay, great. So let's go into our code and let's create a new file. Of course, Python file. And we're going to call this while loops and hit Enter. Great, so now we have a new file while loops and I go to issue a challenge. So your challenge is going to create a for loop. We already know how to create a for loop. So you're going to create a for loop that iterates over a certain range and print out the index at every iteration. We've already done this. So I just want you to create this loop and then we will convert it into a while loop. So you understand it, but pause the video right now and go do the challenge. Hey, welcome back. So we're going to write for I in range, and let's pick a small range. We don't want it to be a very big range, so we'll just write nine. So it goes from 0 to eight. And in here we're going to write print r equals a replacement field dot format. I hit enter in here and we're going to run while loops. There we go. I equals 0, I equals 12, until it gets to eight. Okay, great. So now we are going to write, print a star and we'll just write it 30 times just to differentiate between the for loop and the while loop. So in here, first of all, we're going to create a variable which is going to be the I and we are going to set it to 0. Then we are going to write while I is less than 9, we are going to go ahead and print out i equals a replacement field format. Hi. And what we have to do inside of a while loop, we have to add a plus one to it. So plus one. So we've already seen what this does. It takes the eye and adds one to it. It doesn't replace the eye with a one. So what is happening in here? First of all, let me run the scope so you believe me that the while loop exists and works. So we run the code and as you can see, let's make this bigger. This is the four and this is the wild in here. And you can see that they are exactly the same. So what is happening in here? First of all? Unlike the for loop, we actually have to create the variable above it and we have to set it to a certain value. This happens on its own in the for loop. Then we need to create a condition. So this is the condition until i is greater or equal to nine, we will keep looping through this while condition and we are printing out the eye every single time. Now, what is the I plus equals one and why are we adding it in here? And unlike for loops, where the eye increases by itself as we give it a range in a while loop, we actually have to do this manually. Now, this is a bit cumbersome, I know, but this is very helpful and you'll see how later on when we have conditions, we add different condition doesn't have to be comparing a certain variable to a certain value. It can have multiple applications, just like we have an hour IF statements. So we start off with an I equals 0. We check if the I is less than or equal to nine. If it is, then we enter into the while loop, we start to printing. Then we add one to it. So this becomes a one, then a2 and a3 and so on. And let me show you how that looks in a debugger. If you want, you can pause the video here and do it yourself. So let's debug our code. And in here we can see that when we run the code, we enter into the while loop. We increase the I by one and then we have I equals one. So it's in here. Then we loop through again I equals two and it's putting it in here maybe. But let's just do something a bit different. So we're going to change this to a j, this one to two a j, this one to a j. And everything is going to be changed to a j. Now we debug the code again. And now we can see it was because we already had an eye up here. It was using the eye again in here. So now we have a j, we have a separate variable. We step through the code, you can see that it's less than nine. We print out j. Here it is, j equals 0. We increased j by one. And as you can see now j is one. And we check, is j less than nine, is we print out j equals 12345678. Finally, we get to J equals nine. We go to the while loop. Now, is j equals nine, less than nine? No, it's equal to nine. So what's going to happen here? We are going to step out and the program is finished. So I hope you understood how while loops work. In the next video, we are going to be delving deeper into while loops. So with that said, I hope you enjoy it and I'll see you in the next one. 43. Deeper into while loops: Welcome back, My favorite Python developers. In this video, we are going to learn some ground rules for the while loop and the difference between it and a for loop. And then we are going to use the while loop and it's appropriate place. So let's not waste any more time and let's get started. Okay, so before we delve into while loops, there are a couple of ground rules that we'd need to establish. First of all, you need to understand that we never use while loops to iterate over ranges. That's why we have for loops. But this was just to demonstrate and make sure we know how it works. And now there are two things to consider. First off, we need to initialize the eye, of course we've already done that. And second of all, we always have to have a place or something inside of our loop that will move the condition for word just like we have the J plus equals 1 and year or something that will turn the condition to false. So if we, for example, remove the indentation in here, we no longer increase the j, we have S equals to 0. If we run the program, you'll see that the program keeps printing out j equals 0 into infinity and your PC will finally crash. So let me stop it right here. So you always need to have something inside of your while loop that changes the condition and makes it false, otherwise, the while loop will go on forever and we don't want that. Now, for example, let me show you what this looks like. If we change this to true, this loop will continue on working forever. So we run the code and you can see that j is always equal to 0 because the condition here is true and the while loop never stops. So we need to avoid this, or we'll see later on how we can actually go out from here. Anyways, let's continue on. Let's now get, get a better. Let me just put back the indentations in here. So tab and j less than nine, lowercase j. So now let's go ahead and create a new file to test out a real application of while loops. So we're going to create pizza topping. Okay? So first of all, we are going to create the available toppings. And what does a pizza have on it? So it has pepperoni. It has meatballs. Not sure. If you ever tasted a pizza with meatballs on it. We have cheese, of course, who doesn't like cheese on their pizza. And finally, we have the most headed product ever on a pizza. The pinup. I personally like zooming. Now. We are going to create a another value variable that is the topping. Chosen and it's going to be a empty string. And now I'm going to issue a challenge. So your challenge is to create a while loop. So create a while loop that keeps asking for an input. And the input should only stop when the topic chosen, topping chosen is the available topic. So as we've learned, there is a condition that will make the loop stop. And that condition should be if the topping chosen Nv available topics. So with that said, pause the video right now and go to the challenge. Okay, welcome back. So first of all, we're going to write while. Then we're going to check if the topic chosen is not in the available toppings. We are going to go ahead and ask for the topic chosen well for the input. So choose a topping for your pizza. Okay, rate. And finally, when need to print, I hope you like on your pizza format. And what should we add in here, the topic chosen? So what's going to happen in here? First of all, we've created the topics chosen. It's a variable, it's an empty string. And then we created a while loop. And this while loop will only stop when the topic chosen is in the available topic. While the topic chosen is not in the available toppings, the topic chosen will, well, the program will keep asking us for an input which will go into the topic shows. So let's test this program out. So choose a topic for your pizza. I want cheese. Hit Enter. Hope you like cheese on your pizza. Let's try this again. I want apples. Nope, choose a topic for your pizza. I want the fruits. Dope. Choose a another topic for your bids on. As you can see, whatever we write in here, unless it is inside of the available toppings. We will keep getting asked for topics. So meat balls and the great hope you like meatballs on your pizza. So I hope you did the challenge. I hope it wasn't too hard if it's still not very understood what while loops do and how I made this. Rewatch the video, make sure you understand what is happening. And the next video we'll be applying continue and break to our while loops. So I'll see you then. 44. Break in a while loop: Welcome back, My favorite Python developers. In this video, we will learn how to use a break inside of a while loop. So this is very similar to the break in the for loop. And we're also going to make our code in here just a little bit more robust. So let's not waste any more time and let's get started. Okay, so what we're going to do is we're going to allow our customers to exit out. If he doesn't want to choose a certain topping, if you don't want to be barbaric with him. So we're going to add a condition in here under the topic chosen input that if the topic chosen is equal to quit, then we are going to break out of the loop. So now we run the program. And the problem here is that we didn't add these two columns, occasional, choose topping. This no, no, no. Finally we write quit and we exit out. But there is a small problem in here that the last message, hope you like your, hope you like to quit on your pizza. Who? We don't want that We will fix this later on, but for now, I want something different. I want to fix something different. So if we add a couple of things, if I write quit with an uppercase Q, you can see that we still are asked for a topping and we do not quit. So this is going to be part of your challenge. So your channel's going to be to use a case folds. So make sure that we can write quit however we want without having to worry about the case. If you already know how to do this, we've already done this before. This is just a small refresher. Pause the video right now and go to the challenge, if you, for our gut, how I recommend that you go and search for it on the web. So you get in the habit of looking up things that you're not sure how work or you can just wait for a hint. So use case fold in order to finish the challenge. So pause the video right now and go do the shallow. Okay, welcome back. So I'm going to stop the program right here. And on the topic chosen, I'm going to use case fault. And again, in here, we can also add it to the topic chosen in the while loop. So we hit play. And we can see that we start off, let's say we choose a pizza. Pizza, No, we can choose a cheese with CHE being capitalized. Okay, So this works. Again. Again, let's try quit with a capital Q and D hit Enter and hope you like, quit on your pizza. So for now this works. I hope you do the challenge. I hope you remember what case pole does and I hope you understood how brake works. So I'll see you in the next video. 45. Random Number Generator and Importing: Welcome back, My favorite Python developers. In this video we are looking at back at an old program that we've created, but now we are making it much, much better. So we are going to learn about random. We are going to learn how we can import different, different libraries. We are going to make our code more dynamic, and we are also going to give much more chances to our player to guess the age of Nicholas flatMap. So that said, let's not waste any more time. This is a big video and let's get started. Okay, so if you remember, we've created a game previously where we tried to guess the age of Nicholas finance. So let's go to that project. So we're going to open the project in here. We're going to open up the program slow. And new window that's working in a new window. And let's go to the Nicholas flam male age and there is our coat. So the problem in here, there are actually two problems. The first one is that it's not a really fun game if the actual age is always the same. So we're going to try and add and make it more random. And the second thing that makes us came not very fun, is that we can only try to guess two times, so we need to make it infinite. Let's go ahead and do that. The first thing we're going to do is we're going to import the random library. So we're going to write important here and we're going to type in a random. Now what this allows us to do is it allows us to import the random library and now we have access to it. And what libraries are, they are a collection of code that have their own methods in them that we can use an order two, do different things that we couldn't usually do. And why do we need to import them? Well, because they are big libraries and sometimes we might rarely use random. So this is why we need to import them beforehand. For example, case fold can be immediately used without importing anything. So now we're going to create the actual age, actual H. And it's going to be instead of a standard number, we are going to type in random. And this is what I mean by using the methods that are available in it. We can use the rand int. And you can see right now if you hover over it, it returns a random value between a and B. So we can choose a and b. We're going to choose one and 20. So the random number, a random number between one and 20 will be generated using the method rand int that is available inside of the random and it will be assigned to the actual H. Okay, great. So now if we run the code, okay, we run the Nicholas Florimell h. So what is flamingos age? Weasley. Six. Mr. Weasley, get slower. 3. Wo we guessed it. It was totally random and we guessed it. Let's try again. So let's say five. Please guess higher, 9, wrong gangster recently and we can cheat a little bit so we can print the actual agent here. So we run the code, so it's 15. Let's see, three gets higher, 15. Well done, Mr. Weasley. Great. So our code is working. So 11, we get 20 points because we guessed correctly on the first time. Now the next thing we want to do is we want to make it a little bit more, let's say dynamic. So instead of simply using a standard 220, we can actually type in here that the highest underscore age should be equal to 20. And instead of using just one to 20, we can use the highest age. And in here, what is flamenco as agents to Weasley? And we can add two parentheses in here just to indicate. So it's going to be between one. And we'll use a replacement field and add in the format that the highest age. So now when we run the code, you can see that seven, let's say we want the highest H to be 60. We rerun the code. Yep, we run it, so now it's 50. Let's say we want four. Nope, Guess how your 50? Great. Now, let me just add a comment in here that we are going to remove this later on. So remove this later on. And now what we want to do is give our player a chance to guess multiple times. So it's time for a big challenge. So your challenge is going to be to modify your code using while. So first thing you'll need to do is create a while loops. While loop that keeps asking our player for input until he gets the correct h. Next, you'll need to keep the if-statements that we already have inside the while loop. And finally, test if the player should go higher or lower. So basically it's the same code almost, but you need to transform it into a while loop that keeps asking us for input until we get it right. So this is a big, a huge challenge. So take your time, pause the video. Give it at least, at least five minutes of or even 10 minutes of concentration to try to get it right. So pause the video right now and go to the challenge. Oh, okay, welcome back. So what should we be doing in here? First of all, let's go ahead and create our while loop here. And it's going, the condition on it is that it will keep asking us as long as the guest is different than the actual H. So because we get, are getting the input and here we can move this down under the while. And we are actually going to create a variable in here that will keep track of the gas. And this gas is going to be, of course equal to none. Okay, So as long as the guest is different than the actual age, this while loop will continue on working. Now in here, what we are going to do is we're going to, first of all check if this is the actual H and else we are going to compare the guests to the actual age. And if it is, then please guess higher. If it's greater than that, we'll need, then we'll need to guess lower. So this stays the same, That's just tablet inside. So now it's part of the while loop. Then what we're doing is getting a second guess and then checking it again. So we don't need this code anymore. So we can delete it. Great, So what else is missing in here? Let's run this code and see what happens. So we run, what is females age 50? Please get slower. 20, please get slower than Please guess higher 12, Please guess higher 15. You guessed correctly 20 points for garage door. Very nice, very nice. So as you can see, the code is working correctly. If you have a different code, but it works that that is 100% perfectly fine. If you haven't done the challenge because it was scary. Here's another mini challenge for you to complete. So what we want is we want our player enters 0. We want to break out of the loop. So go ahead and do the mini challenge or case. So after we get the input, and here we are going to check if the guess was equal to 0. We are going to print out, Okay, hard luck. And then we are going to break out of the loop. So now when we run the code, let's say fifty two, fifty one, thirty eight, lower, higher. Okay, So 0. Okay, hard luck, and we stop the program. Very nice. Now, the problem now is that if you want to guess between 1100 thousand, that is going to take ages. So in the next video we are going to discuss an algorithm that will allow us to guess much, much faster. So I'll see you in the next video. 46. Binary Search Algorithm 00: Oh, okay, so let's first of all take a small example so we can understand where we can use binary search algorithm. So let's say for example, we have a class full of students, or we have 50 students to be exact. And we want to give each of them there. Great. So let's say Michael comes up and now we need to give Michael has a great. First of all, how can we do to swell weekend? Go ahead and start looking through all of the grades. And one thing to keep in mind that these grades are all listed or ordered alphabetically. So we start off with Abby, Ben, a car, and let's say we get to Zach. So we can do we can either start looking through each and every name until we get to the m, which will take a long time. Or we can go ahead and split our list of names into two parts or our list into two parts. And if we see, for example, that the last name of the first part is Jack, that means that because m comes after j, that means that the name Michael is in the second pile of our list. And this is what we can do using binary search. We can also do this. Do this again, take the second, which is now 25, divide it by two, and then search through where the letter M should come up. And this will greatly reduce the number of trials that we need to go through. And this is what we are going to implement in our game. So let's take a real-world example and see how it works with real numbers. So binary search algorithm, let's say we need to guess a number between one and 10. One being the low, ten being the highest. We are going to use this formula. So we get the low plus high minus low divided by two, and we use the two forward slashes and ordered to remove any floating point. So where is the midpoint of one between 10 and before we continue on, of course we are going to choose a number. I'm going to choose, for example seven. So we calculate the midpoint. So as I've told you, nine divided using P2P forward slashes by two is 4 or four. But because nine divided by two is 4.5, when we use the double slashes, we get just for. So after using the formula, we get that the midpoint is 5. So what we do is we remove everything because we want to guess higher. We know that it's seven. We tell our computer to guess higher. So he removes everything from the low to the middle, and then he calculates the middle again. So now we get the low as the six, the high as the 10, and we calculate the middle, we get the eight. So what we tell the computer now with a 100 to need to guess lower. So he removes everything from the middle, The high, and now we have the middle as the six after we do the calculations. So now I, again, the PC asks us, should we get higher or lower? Well, we tell him because it's seven, we want him to guess higher. So he removes the six and we get the answer seven. But any normal human would know that this is seven, but because it's a computer, it's still is not very smart. He does the final calculations and he checks, he realizes that the high is equal to the low. So this means that the right answer, the correct answer is C. So as you can see, we always remove the middle. So when we want to add a plus one to the low end, when we should guess higher and minus1 to the high-end when we guess low. So no challenges in here. Maybe the challenge is to rewatch the video, make sure you understand how this is working. Because in the next one, we are going to be implementing this, these formulas and these spine and the binary search algorithm into our game and making our code or game or our computer much smarter and dynamic. So I'll see you in the next one. 47. High Low: Welcome back, My favorite Python developers. In this video, we are actually going to create our first little bit complicated game using Python. And it's going to be a high, low. And we are going to be implementing the algorithm that we just learned in order to teach our computer how to guess a number that we are thinking of using high or low. So let's not waste any more time and let's get started. Oh, okay, So well, let's go ahead and create a new Python file and new, and we're going to call it high, underscore. Low, hit Enter. And let's get started. So the first thing we're going to do is we're going to create two variables and here, 140 low and one for the high. And then we're going to print out some instructions for our player. So choose a number between. And these are two replacement fields. Of course, it's going to be the format and the low. And the high. Okay, great. And down here we're going to give or get an input. Press any key to start. So we are going to tell our player to press any key to start because we are going to be asking him for inputs every single time. So this is just a customary thing to do. So we're going to create a while loop that will be true all the time until we choose to go out of it using a break. We might change this later on, but for now, let's just keep it very simple. We are going to focus on implementing the algorithm that we learned. So as we've discussed, the guess by the PC, It's going to be equal to low plus the high minus low. And it's going to be divided by two. And we are going to keep it as an integer. We don't want any float, floating point numbers. Then we are going to take an input. So we're going to call it high or low, underscore and put and you can name your variables what everyone, just make sure that your variables always make sense. So we're going to take an input, and in here we're going to, I guessed. And this will be the PC guessing. And then we are going to prompt the player for a couple of things. So we're going to skip on a second line. And here we are going to tell him If the PC needs to guess higher, then you will need to guess, I mean, the L 40 lower. Then we'll skip a second line going down here. We're going to ask if the PC needs to guess higher. And finally, we'll tell also the PC. Or we are going to prompt the player 2 plus c if the answer was correct. And we are also going to skip a line. And finally in the format, we are going to get the GSPC. And we are going to use case for just in case the player of our game wanted to maybe put a uppercase C or uppercase, H or lowercase, so it won't matter. Okay, so what is happening in here that's review one more time. We are prompting the player to press start. We have a low and a high. We tell him that he needs to choose a number between the slow anti and now his PC wants to start guessing that number. So we're going to take the low and the high. We're going to use the input of the algorithm that we've learned. And then we are going to take an input from the actual player to see if the guess of RPC needs to be higher or lower, or if he casted correct on the first time. Now, before we move on, we need to create an unsafe condition for each of the three inputs. And that's going to be your challenge. Your challenge is to set the LF conditions, so create an outlet for each of the inputs. And you don't need to write anything inside. Just make sure to check for the inputs and the LFTs. Because the things that we are going to add inside are going to be a bit different. You can only maybe add some code to the input of the sea and that case. So pause the video right now and go to the chart. Okay, welcome back. So in here, after we give the computer and input, if the high low is equal to h, we are going to simply add a comment in here that guess, higher may claw and one greater than gas. So this is just a reminder for us later. Then we are going to use an LFO. High, low input is equal to L. That means that V guess lower. And we need to make a high and one less than guess. And finally, an LF for the high, low input. If it was C. And just print out the when. And in here, as I've said, we simply need to print something out. So I guess it in and that's it. And in here we are going to later on at some, a way to count the number of guesses tried. So maybe, as we've said, the minimum number or the maximum times that the computer needs to guess it correctly will be 10. But maybe, maybe he gets the number on a tries or maybe even some. So you might have noticed if we run the code right now. Okay, so right-click, run high, low, and as you can see, we have an error in here, and it's expected an indented block. So what's the problem in here? And some of you may have already tried to run the code and noticed that there was an error. So what's the problem in here? Well, we already saw what's the problem? We need to add a pass and here because we can never leave a conditional statement with an empty block, so we always need to add something. And in our case, and here, we can simply add the past. So the past doesn't do anything. It just makes the code correct. It's just a place holder for our code. So in the next video, we are actually going to be filling our conditions and creating a formula for the PC to continue on and guessing until he gets the correct answer. So I'll see you in the next one. 48. Completing our Game: Welcome back, My favorite Python developers. In this video, we are going to translate the formulas that we'll learn in the algorithm to actual code in our game. And you'll see how efficient this game really is. We are also going to be creating a counter that will count the times that it took the PC to guess our number, the number that you will have in your head. So let's not waste any more time and let's get started. O k. So time for the fun part, time to translate our mathematical formulas into code. So in here, as we can see, this is the power of using comments. We can see that this is the gas higher. We need to make low-end one greater than t gets. So in here we are going to get the low end and it's going to be equal to the gas by PC plus one. Then we have indicates where we press L, This is the guests lower. We need to make the high-end one less than the gas. So we take the high, it's equals to the guests of the PC and it's going to be minus one. And finally you, what should we do after we check for the LF? The answer was correct. We are going to break out of the loop so we don't go over it again. And finally, we need to take into account that maybe our player wants to play a small dirty trick on us. So else, if he presses anything other than the H, L, or C, he will be prompted with the message. Please. Only press L, H, or C. So we don't need a comma in here. And I guess this is about it. Now the last thing that we want to do before we continue, we want to actually go ahead and count the number of times that it took our computer or PC and order to guess it. So this is going to be part of your challenge, and it's a bit of a hard challenge. So you'll need to count the number of times the player tries to guess. So create a variable outside the while loop and initialize it. So this will be of course, the variable for the number of guesses and increase it every time the player doesn't guess correctly. And finally, print out the number of guesses. We already have a place to print out the number of guesses. So go ahead, pause the video right now and go do the challenge. Welcome back. So first thing we need to do is we need to create a variable, so number of guesses, and it's going to be equal to one. So some of you may have initialized this at 0, but we are actually going to initialize it at one. Why is that? Well, because as soon as we enter the while loop, we already have a guest by the PC. So this already counts as one. And then we have the second one after the player chooses whether the PC needs to go lower or higher or if the answer is correct. And finally, where did we print out? Yes in here? So we are going to type in format and it's going to be the number of guesses. And where should we be adding one to the number of guesses? It should be in here after we check everything. So number of guesses will be plus equal to 1, go rate. So this is our code. I think this is all of it. And let's go ahead and test this out, see if it worked. So we're gonna run our program. Let's make this a little bigger. So choose a number between 1, one hundred, ten hundred. Let me think. I think when 260. So hit Enter, I guess 500 to a 160. You need to get slower. 250. You need to guess higher, lower, lower, lower, lower, higher, lower or higher. 260, very you go, as you can see, everything is working correctly. So now if I press the C button, hit Enter and as you can see, I guessed it in 10 trials. So you want to go ahead and count them. I'm sure that this is correct. And as you can see, our program is working correctly. So have fun, test this out, make sure that it gets all the numbers. Let's try this again on some higher number. So let's say 683. So 683, higher, 683, lower, 680, very close. Lower, higher, higher. Nice. So as you can see, he guessed it in less than 10. So that's very impressive. And unfortunately this is not an AI. He is not getting smarter. It was just a coincidence. So go ahead, test out the scope, makes sure that he guesses most of the numbers that you choose him to guess. And you'll notice that almost he can guess. All of. He can guess whatever number you are thinking of in ten or less tries. So with that done, I hope you enjoyed this fun game. We will be coming back to it and making it a little bit smarter. In the next video, we are going to learn about L statement. But this time it's going to be four loops. So I'll see you there. 49. Else Statements in Loops: Welcome back, My favorite Python developers. In this video, we are going to learn how we can add an else statement to a for loop. So with that said, let's not waste any more time. And this is a very easy video and let's get started. Okay, so some of you might be thinking, Michael, there is an else For loops. Also a Yes, there is. So in order to understand how they work, we are going to create a new Python file and here, and we're going to call it else in loops. And double-click in here, and let's get started. So first thing we're going to do is we'll create a colorist so-called list. And it's going to be a very simple list where we have square brackets. So BMW car, a Ferrari, a Ford car. All the core. Oops, core. And a Tesla car, my favorite kinds of God. So we are going to create a for loop. So for code and CAR list, if the string call is not in the core, then we are going to print out, sorry, this list is an acceptable. And we are going to break out of our loop. So as you can see, we are looking for the string car inside of each car and the car list. And if one of them doesn't have a car, we are going to print out, sorry, this list is unacceptable. So right-click, run else and loops. And obviously this list is not acceptable. Okay, great, So this isn't working. We need to add a car to February. Very nice. Let's write code. Let's run the program. And unfortunately, as you can see, we don't have any output telling us that actually this list is valid. Great, you can work with it. So what can we do about it? Well, we can add an else statement to the for loop and I'm a bit tired right now, so it's going to be your challenge. Your challenge is to add an else statement. So add an else statement to the loop just as we do with the if statement. And simple simply print, this should be simply print something to the console like congratulation, this list is valid or anything you want. And the most important thing is to mind the indentations. So pause the video right now and go ahead and do the challenge or K walk on back. So I focused on the indentations because if you don't get the indentations right, you might end up adding an else statement to the if, and this is not what we want. So let's go ahead and add an else, the for loop. And we are going to print out a great. This list, of course, is valid with a couple of exclamation marks. So if we run the program right now, you can see that great, this list of goals is a valid. So what's happening in here? It's very easy, just like we have an else statement for the 40 if statements. Whenever the condition passes, we go to the else. We also have an else statement for a loop whenever it finishes without breaking. So right now let's remove the car from Ferrari. And we run the code again. And you'll see that we don't get this message printed out because we are actually breaking out of our loop and we are getting the message solidus list is an acceptable. So we are not entering the else because the loop is not actually being carried until the end. So what that little knowledge right now, we are going to use this else statement to make our previous game much better. So I'll see you in the next video. 50. Else in High-Low: Welcome back, My favorite Python developers. I'm not showing you the code because there is a big challenge in this video. So now if we run the code, you'll see that we can choose a number between 1, one hundred, ten hundred. I'm going to choose 100 because I noticed that this works for us. So I guess 500, Let's get slower. I guess 250, lower, lower, higher, higher, lower, 101, lower, higher, and 99. We have chosen 100. Remember when we hit Enter, you can see that I guessed it in ten tries and you're thinking of 100. Whoa, how did that work? You will see, and actually you will be the one that writes the code for this. So let's not waste any more time. This is one of the longest intros and history and let's get started. Okay, so let's go back to our amazing game in here. And now what we want is for our AI to know when he has guessed right and not ask us anymore. And how is he going to do that? Well, we can do that by checking when our heart is equal to our low. And when that happens, that means that the answer is the correct one unless he guesses it by accident beforehand. So the first thing we'll need to do is to change the condition on our loop. And it's going to be part of your challenge. So yes, you are the one that is going to create or enhance our AR. That's how much I trust you. So change the condition on the while loop to stop when high is equal to low. And add an else statement for when the loop finishes. And if you already know what to do, pause the video and go do the challenge. If not, and you need a small hint. The while condition should be high is not equal to low. So if you're not sure why, you need to take a little bit of time to understand why. So pause the video right now and go do the challenge. Come back. So the first thing that we need to do as we need to change this true, too high is different than a low. And why are we doing this? We want this loop to continue on working as long as the high is different than the low. And when the height is equal to low, we are going to create an else statement for the loop because we are outside of it. So we finished high is equal to low. And in here we are going to print. So I'm going to simply copy the line in here and add it in here. And we can actually remove the comment we already counted. And we'll also add a second to print. And we'll tell him you guessed or you were thinking of format. And we're going to give it the high or we can give it the law, it doesn't matter. The answer is going to be the same. So what's going to happen in here? The loop will continue on looping while the high is different than low. When high is equal to 0, we will exit out of the loop. And we are going to print, I guess that in the number of guesses and you were thinking of the number high. So with that done, let's run this program. So run the program. Okay, right-click, run high, low. So choose a number between 1 and 1, 0, 0, 0, 0, 0, 1, 100. So lower, lower, lower, higher, higher, lower, lower, higher, and higher. And as you can see, I didn't proceed. Less input that I added was H, and I guessed it in ten guesses. We should have added guesses in here. And it guesses guesses in here that I not notice it less time. And you were thinking of 100. So how cool is that? It can almost scale you how crazy this is. But let's try a different numbers. So we're going to try maybe, let's say six hundred, eight hundred and ten. So higher, a higher or lower, lower, higher, higher, higher, higher, and there you go. So we have to proceed in here because it guessed it before we could get to the last gas. So this sometimes won't work. You need the number that, that takes 10 times, but as you saw, one of them worked, it will be hard to pick another number that will need ten guesses.