Introduction to Python: A Practical Approach | Ashraf Madhoun | Skillshare

Introduction to Python: A Practical Approach

Ashraf Madhoun, An Engineer with +10 Year Experience

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
13 Lessons (1h 50m)
    • 1. 1 Introduction

    • 2. 2 Why Python

    • 3. 3 Download and Install Python

    • 4. 4 Hello World and Help Function

    • 5. 5 Variables and basic data types in Python

    • 6. 6 Commenting your code

    • 7. 7 Reading keyboard input

    • 8. 8 Exercise Build a program to say Hello

    • 9. 9 Exercise Build a simple calculator app

    • 10. 10 Conditional Statement

    • 11. 11 Loops For Loop

    • 12. 12 Loops While Loop

    • 13. 13 Exercise UserName and Password


About This Class

Learn Python easily and unleash the power of Python coding using Real life examples and Practice activities

>>>Learn Python easily and unleash the power of Python coding using Real-life examples and Practice activities. <<<

Welcome to this course.

Python is one of the most popular and fastest-growing programming languages in the world. It's used for all sorts of tasks including web programming and data analysis; and it's emerged as the language to learn for machine learning. That popularity means that python developers are in demand and python programming jobs can be lucrative.

These are all great reasons to learn how to program in Python. This module will provide an introduction to using Python to build an app that can be a starting point for becoming a Python programmer.

Why You Should Learn Python?

  • Easy to learn.

  • Supports quick development.

  • Cross-platform.

  • Open Source.

  • Extensible.

  • Embeddable.

  • Large standard library and active community.

  • Useful for a wide variety of applications.

You’ll learn how to:

  • Explore the choices available to run Python apps

  • Use the Python interpreter to execute statements and scripts

  • Learn how to declare variables

  • How to take input and convert it

  • How to send output in more than one method

  • Build a simple Python app that takes input and produces output

  • Build a simple Calculator using Python

At the end of this course, you can create Innovative Projects using Python. The only thing that you need to do is THINKING, WIRING & CODING.


1. 1 Introduction: hello and will come its new course in what you are going to learn. Piper, this is an introduction to buy. Concourse Presented to You by Ashinoff Python, is one of the most popular on fastest growing programming languages in the world. It's the third most used according to Get Hub in 2019. It's used for all sorts of tasks, including Web programming on that analysts on its managed as the language to learn for machine learning. That popularity means that part. When developers are in demand on python programming, jobs can be lucrative. There are all great reasons to learn how to program it by phone on. This course will provide an introduction to using Python to build an AB, which can be a starting point to becoming a python programmer. It will be the first course off a series of courses which will help you master person programming in no time what you learn in this course, you will explore the choices available to run python abs in different machines. When those Marc Andre knocks, you'll use the Python interpreter to execute statements and scripts. You will learn how to declare variables, different type of variables Andi. What ish dive variables does on why and when you need to use it. How to take input and converted to fit your AB goal. How to send out Put in more than one method on how to build a symbol python script or AB that takes input from user on produces output depending on a certain algorithm. It will also, and how to commit called on why you need committing. You learn why by phone is great language for programming scripts on how to build a simple calculator Using python language, I'm sure that you will enjoy this course content. I can assure you that at the end of this course, you will create two or three Python scripts. One of them is a simple calculator app that you can show off to your friends on. It will be a starting born for your python. Courage. Thanks for watching this introduction. See you inside 2. 2 Why Python: hello and will come this new lesson. Now let's talk a little bit about rifle, but in development started in the 19 eighties. Andi unpopular in the last decade or so, Python three point X is the future of five. Phone. There's bison to underst websites. Still use by phone, too, but you should learn bath. And three. There are changes between bison to on both on three solid fly breeze that are not supported on. Do you have to make sure that you are learning the most trending? One by phone is on interpreted language. It's a very high level programming language, so it requires a lot of decoding. Andi interpreting on it takes a lot of processing power. It supports a multitude of programming bargains. It supports object oriented programming, functional procedure logic. Structured on a lot of other things. It's a general purpose programming language. This is why it's a very trending language, and a lot of people use it all around the world. It's very comprehensive. Standard library includes numeric models, crypto service operating system interfaces, networking models, GeoEye, support on development tools among off a lot of other ah general pair boss libraries, Andi techniques now, when it comes to by phone, it's a very easy language when it comes to learning how to program using this language. It supports quick development on its aboards cross platform so you can vomit Lennox Windows on Mac. It's an open source language. You will find a lot of projects on the lot libraries available for free online so that you can use on download easily. It's unbeatable language. You can embed python according in almost everything. It's extensible language on. It has a lot of standard library on active community. If you have a question you will find, I want people to answer your question. It has a very active community that will help you gain knowledge and solve your problems in no time. It's very useful for a wide variety of applications, like Internet of things on other applications. This is a sneak preview. While you should learn by phone on why powerful is a very great language to start with. Thanks for watching this quick intro. This is Ashley from 3. 3 Download and Install Python: getting started before we begin. We need toe. Actually install python. The first thing you should do is download and install python environment. All instructions on examples will target this environment. This will make your life away much easier. No. When we come toe installing or downloading and installing python, we have more than one option. You can choose on install on editor of your choice for Lillis users. I prefer sublime text. It's a very interesting and widely used editor. I will show you this editor and I'm in it. For Windows users, most Windows users use ideally or the integrated development environment provided by Pi phone, which is the default one. Options or other options include them Imax Not bad Blast Class Pie, Chart, Eclipse or any other software that you feel comfortable when using Throughout this course. I'll be using Pi charm you know, Windows environment for all of our demos so you can use any other one. The coding is the same, but make sure that you know the software that you are using. Now let me show you the sublime text editor on the Pie chart editor and let's in a stall Python now to install python goto any search engine on right? Install python. The first result is download python from person. That or now what you need to do is download python 3.8 point three. You can't go with any older version. As you can see, we have 3.73 point 63.5 type affair working with the largest one, So click here once and as you can see, we have other peaks e fine, which is now downloading and installing. Now, once done, downloading will start the installation process on what you need to do at this point. Go to the start menu right click and open the CMD or Windows Power shell as an admin. Now, if you write by from here, you will get an answer. As you can see, I have points and 3.8 point two installed already installed on my system which is under the machine on now we can install python 3.8 point three, which is the latest version So click open file. No, since I already have 3.8 point two, I have upgrade now option. But you will get install now on what you need to do is simply click ones on the installation process will start. It will take some time for python tour being installed on your system on. Once it's done, you can make sure that python is installed by chicken. This using a command window. Now let's leave it now. Go on, right sub line text. Any thought? As you can see, this is the I call off the software Click ones on. This is the software itself. As you can see, it's a very nice software that you can use for writing codes you can download for Windows Click ones here. And, as you can see, the download process started, not Barton is still installing. It has a little futures. It's a sophisticated takes digital for court markup on pros on Do you can use it for any programming language, not just Pyfrom on. We also have by Charles on Pie Charm comes in a free and bayed versions, so what we need to do here is download the free version. As you can see, this is at the download option for my Child Click download, and now you have two options. You have Windows Mac or Lennox. Choose your operating system. I have windows. If you went with professional, you'll try it for life 30 days. Then you'll have to pay on the community. Addition is more than enough. So click download for that community option on as you can see, the Lord started. Now let's install the sublime text editor. I'm showing you have to download and install each of these. But you have. You only have to choose one. So click next in a stall and now the installation process for sublime text editor started. Click finish. Now, if you want to see it, you can simply go. Takes a little. Here it is click ones on here you have here we have the sublime text editor on from here. You can simply change the proprieties for this software. You can go to view syntax and choose the programming language again. View syntax on select python from here. Now, once you sell it python, it will color your codes depending on the language that you're using. Since this is a pH, we called won't be corrupt correctly again. You have to go to view on syntax, then python to make sure that our selecting the by phone in violent. Now the next thing is, you have to go here, sit about successful. Now we have python 3.8 point three install. Click close. Go to the start menu. Right click. Choose Windows partial or command as an admin click. Yes, now to know that python version and if my phone is installed just right by phone and as you can see, bison 3.8 point three is installed in our system. That's it. This is how easy it is to install bite on your system. Now we have a fight on this. Told on we have sublime text interested. Install. I already mentioned that I'll be your using pi charm text editor. I prefer this one. So let's close this one. Let's download. I went down with it by charm. Let's install it Now we are installing by charm, text editor or according editor. Click Next. Now select the by child from a vision that you want to uninstall. Since I already have a virgin, I want toe uninstall it on. Install the latest version. Click next the next. Now we have the 2020 vision click next again choose the 64 bit launcher at open $4 project if you want it at lunch at the i R to the bath on associated with Python files on its told us that 64 bit lunch or since I have a 64 bit operating system, I marked all of these. Then click next next. And as you can see now it's installing. It will take some time for the installation to finish knife. It's extracting the files, but this is by far the best pie phone editor that I have ever used that provide a lot of functionalities. You can create projects on create files inside these projects on. You can easily run your vital file. Track your errors on debug your coat. Andi. Best of all, it's free off charge. It's a community version, so you can use it without any restrictions. Now it will ask you to reboot your system, and you should report it. But for the circle this lesson I want. So I want to manually reboot it later. Click finish. Now, if you into the start menu, you will find by charm community addition installed here like ones to start the software. As you can see by chahm 2020 now. All right, you need to do is simply create new project by clicking here. Or you can open up on all project from here. All you can open any all file from here. I will create new project on Let's call it. Hello worked. Okay, now we have everything up on 30. Just click create. You can choose this new environment or on existing environment, which is AARP iPhone that eggs e file interpreter. Well, you can go with a new environment option, which is this one. Now let's create Leave everything to its default. Just change the name of your project toe. Hello World and click. Create now to re create virtual environment so that you can use it to program or to start writing your very first by so called usually takes some time when you are running it for the first time. Now it's downloading the necessary libraries, so you have to be connected to the Internet. Different. Both fix on configure automatically. That's it. A band ready? This is your project, and here you can create your own scripts. You can add new file or new price on file, and you can name it. Hello Worth. As you can see, this is ratified in the next lesson. They are going to start with our very fair Spieth on program, which is printing the whole world on the council. Fast talking this less on This is actually from 4. 4 Hello World and Help Function: a great way to get started with Vital is learning how to perform in port on output. Inp iPhone The print function, which is one off more than 60 functions built into the language output, sticks to the screen. No, the following statement. Let's start. Go to view Goto. Appearance on I Will enter presentation would toe make my according more clear to you so view a periods Inter presentation would Now, As you can see, I can't start writing here. If you try this function, print inside that you can't like anything you want. You can write Hello World. Now this statement will displays Hello, word on the screen. You can go to run on drawn it. As you can see now we have a word printed on our screen because we use the print function. Now the argument past toe print function is a string, which is one of the fundamental data types and python used to store on banished text by default. Print out puts a new line character, which is this one on the end off the line, so that subsequent output, for example, additional calls to print will start on the next line. We can't just this out by simply writing print, and here you can write Hello, word. Now if you went again on down the court as if and see Hello, World is in one line. Ashraf is a new line. That's it. Now you can try your first python statement. Python supports on interactive council experience, which allows you to type in commands and see the results immediately. This is sometimes affairs toe as a read evil print loop or rebuild, or are a pl. It's written like this are E P. L. Read evil print loop, which means that you can type things and see the results coming up as you type. No, we can try this in our consul window if you want to the start menu on right click to open up the windows. Partial admin. You can easily right apart from here, and it will respond with Python 3.8 point three, which is the bio phone version that we have missed old again. When you type iPhone to start the bison interpreter. Now you have initiated or started the interactive mood. Now the next tip that you can do is try the print command. This is an active window for our consul on Inter Vital interpreter so you can print here you can like hello words. As you can see, it did respond with the very same thing, which is printing Hello work now. The R E P L has a built in help function that you can use to look up keywords and functions . There's centralized syntax for this function. Is writing help at two parentheses on inside them. You can like object, for example, and you will get results toe help. You use objects and python. Now you can try it out for other things as well. Object here is a specific function or keyword you want help on. Let's try a few examples. Let's try to get some help regarding the print function so you can. As you can see, we have more things. The show when it comes to our health. Now what you need to do his click into will see to get out of this. Now we are back to the Python Interpreter window. The active interpreter. We can write help friends. As you can see, we have the result now sitting us. That plant will take these as input on. It explains everything. As you can see, it tells you what city is, what end is on. You can get help for any other thing again. This is a very nice feature that will help you get heaps off. Result now to exit the help screen on return to the Interpreter, you can simply press Q on. You can get out of the help screen now. The interactive help console is a very great feature. If you don't pass on argument to the help function on interactive help, facility is started. If you did type help with two parentheses, you can see that here we have help Onda We can like anything that we want, like a keyword or a symbol for the thing that we want help with. Now, once you write help to interview interactive help console, this will list some basic instructions on how to use the help system. From here, you can just type in the element you are interested in. If you type string to get help on the strength of the time, it will display something like this. As you can see what space is asking God. Lower case digits hex the digits glasses on a lot of other things. Now, if you want to get out of this, you can simply rescue their enter. When there is more than one page off output, you can press in. Tartus blame Ally. As you can see here we have more. So if I pressed enter I will get more results, as you can see line by line. Now, once you hit the end of the help screen, you can type que on. As you can see, I'm out off this window and I can search for any other thing. You can feel free to explore more things. For example, you can get a list off python cures by typing keywords, key words. And as you can see here, we have a few words that we can use and bite. According, if you want to get out, you can simply right Q. And now I'm out of the help section and back to the active interpretation. Now this is it. This is how to use that console. When it comes to python programming, how to use the help features. Oh, the health futures to know more about anything and python you will need the help function in a lot off things in the future, but for now, you just need to know how to use it. You can simply press sprint on between the parentheses. You can type the thing that you want help with, like loss on. You can look for anything now. There are no results for class or classes. You can look for string. You can look for keywords. Andi. You'll get a hebe results again. This is only to get help on Ah, how to use certain keywords that their functions. Andi. It's a very nice future. Now let's go back to our coding section here. We did learn how to Brent, how the world and python on how to plant our name. You should try this out on your machine before moving on to the next lesson. If you have any questions, please ask in the Q and a board. This is Ashraf from 5. 5 Variables and basic data types in Python: variables on basic data types and python variables are one off the fundamental building blocks off programs written in python variables. Hold that in memory. They have names on. They can be referenced by name. Variables also have types, which is which specify what time of data they can store, such as a string or an interview. And they can be used in exhibitions that use operators such as plus on minus to manipulate their values. And python, a variable is declared on assigned a value using the assignment operator equal, which is this sign. The variable being assigned toe is on the left hand side off the operator. So here we can write X, which is are valuable the left hand side of the operators on the value being assigned, which can be an exhibition. Chess is such as to bless, too, and can even include other valuables is on the right side so we can write X equals one you can write why equals takes a blast five. And we can also write Zid equal Why so the equal operator can take two variables on the left and right side, or it can take a variable in the left side and a value on the right side, or it can take a variable in the left side. On a variable, the right side blasts a value, so if you have a heap options and these are only examples to assign numbers to variables. But numbers are just one off. Several data types that powerful supports notice that that there is no time declared for the variable. This is because Powerful is a dynamically typed language, which is a very, very great feature. It means that the variable type is deter mined by the letter assigned to it. In the example here, the X Y and Zed variables will be integers, or internal types capable of storing positive on negative whole numbers. Variable name are case sensitive and can use any letter number on the underscore character . However, they can start with a number so you can't write five. Let's say value this. As you can see, we have a little you need to rename it because you can start with a number, but you can write value five, which is the variable on. Make it equal five. You can even use the underscore, or you can simply write it used the camel case right like this. All right. The value number on this is a very nice threat strategy for naming the variables. You can start the first world with a lower case than every other world with another case. Now all of these variables are integers and we didn't write in X toe. Make sure that python understand that this X is an integer python again Is are dynamically ah tied language which means that you write X equals one. It will understand that one is on integer variable so it will assign a variable X Toby treated as intelligent as you can see x into jar equal one same thing for other valuables If you went to why you can see that why is also an integer variable did equals y And since why is an inter job, Vince? It is an integer value. No same thing applies for other type of variables. So if you did write my name Aunt, you use this. This means that you are using a string variable and we didn't have to write Think as you can see my name String Ashraf Now Python did understand that my name is a string variable because we stored Ashraf, which is as think inside it, and these marks are used to assign strings. Now, if you want to work with numbers, most programs manipulate numbers. Computers treat into Harlem bars on decimal numbers differently. Let's see this example. If you thought X equals one for X equals one point. Oh, now this is an integer. While this is a decimal floating point number because we have other tears, as you can see now by phone creates integers from a built in that a type called and on December miles like this one, which is floating point from bars as instances off float so this would be treated as float variable, and this will be treated as integer valuable by phone built in type function returns a variable data type. The following code that we are going to write will out both times to the screen. So if you write X equals one and use the function type, let's sprint aside vibrant. We need right type, which is a function and five phone on Friday, the valuable name. Now this will print the type variable X. Let's use it here. Type X, no the first X will be integral, while the second X will be float or decimal point. Now let's try this out. Run around Hello world. As you can see, the 1st 1 is introgen of the 2nd 1 is float. This function will attend the type off X and printed on screen, which is basically printing. Float on into your on. This is the result. As you can see, we didn't fight float we didn't write end very powerful again is a dynamically programmed language. So it would understand on its own that this variable is an integer because we did at one. So the variable X and to understand on its own that this variable is flawed because we added 1.0 for variable X on this function can print out the type on the consulate. No, the addition off the boy, zero to the end off one here makes a big difference. And how the programming language treats a value. The death of type impacts how the value is stored in memory and how the process or CPU, and is that that I want evaluating expressions. How did that relates to other data on what kinds operations can be performed with it. Another common data type is the bullion type. Who, Charles the value through part falls now. If we did clear this window, we cannot X equals through now to print the type you can't like. Type on right X here. When you run the cords, you can see that this is bullion data type. Now, internally bull is treated as a special type of insure. Technically, true has a value off one, and falls has a value of zero. Typically, billions are not used to perform mathematical operations. Rather, they are used to make decisions on perform blanching. Nevertheless, it's interesting to understand the relationship between types. Many types are nothing more than specialized version off. More general types. Integers are a subset off floating point numbers and billions are subset off Inter's. So when you are working with variables, make sure that you understand what you are working with and you are choosing the right data type for your application. Now let's try toe print out on look to another daughter, Die, which is things along with numbers. Strings are among the most commonly used data types. Pastoring is a collection off zero or more characters. Strings are commonly declared using a single quotation marks, but double quotation marks may be used toe. So to initialize a string you can write X equals. This is my think, Andi. You can print the string itself by writing print. You can also print the type to make sure that it's a string using the type function that we already mentioned. And you can also use the double quotation toe print out a string so you can live. This is also another way to write us drink now if we did run this village sprinter on a string if we did it on this. As you can see, this is my stink, which is the first print line on the string, which is the time the second line there last line is this one. This is also another way to write a string. Now strings can be added to other strings on operation on as concatenation with the same blast operator. That adds to numbers to add things together. We can simply do this. Let's remove these print lines. If I want to add these two takes together, I can't simply declared a new variable, says it equals X bless. Why now? I can't plant said using the wrong as you can see now, the two strings are printed in the same line and are treated as if they are once drink. We cannot space here to make sure that we have a space between these two lines. Now, if you did that on as you get see now we need a space here. Sorry. Okay, Now this is my string. This is also another string. And we have a space between these two lines. That's it. You learn more about strings in another lesson, including how to parse them on how to manipulate them in various ways. You will also learn about other important data types, such as lists which store collections of data on are frequently used, the whole collisions off strength. But that's it for this lesson. If you have any question regarding any of these data types, I'm here to help. Thanks for washing. This is Ashinoff. 6. 6 Commenting your code: coming to Gil Coat. Most programming languages support, including comments and source code comments. Do not change what the court when it lands. They are ignored by the compiler or interpreter. Instead, they are used to explain how the code works or why it was written. Comments are a great way to document complicated court on to include two does reminding you to come back on. Do something later. For example, You, Cartwright, are not for yourself. Make sure this God works with empty strings. Bottom supports comments using the bound sign or hash, followed by the text off the comment So you can simply add the hash. Andi. But I am government. Don't mind me. I don't huh? Clement's always extend to the end off the line. Andare always one line only for multiple increments. Place abound. Sign at the start of each line. A comment may appear at the start of a line or following white space or code, but not within a string. In that case, it's just a literal bound sign in text. And to show you an example of this here we have. I am a comment. Don't mind me. No, if you're not X equals this. You can write a comment here that IHS off the line is that comment. So it won't People say that about all this string, which is this? This is my thing. Now you can also add another comment here. This is also document No, If you went down on D wrote here, let's let the fix equals and you add a double quotation inside them. If you added the hash sign on draught, this is not excrement. You can see that the hash sign here is treated as part off a string that is stored beside the text. Valuable adding hash sign inside the two double quotation off the string will not make the compiler or the interpreter consider this other string. In this case, this will be treated as a normal text that has that has us hash side at the beginning. Now let's spend the fixed to show you this in action. Now free clicked one. As you can see, this is the hash sign on it was printed on. This is not a comment, as you can see while if you want down here you had a hash outside the double quotation and outside the variable declaration. You can't. This is argument, so make sure that when you write a comment, you don't ah, by mistake added inside the double quotation or the single quotation marks off the string or any other variable declaration, you have to leave white space at your hash outside. Anything on the start writing your comment. Now you can commit each line to make sure that whoever is reading your code can understand that you can right here. This is used to plant that fixed variable on this will make sure that if I took your code, I understand what each lines, what each line means. Now some programmers avoid comments in favour off writing Sylve documenting court, which is easy to understand as a result, off descriptive, variable and function names. So we'll find them writing a sort of X. They were right. Let's say first you don't no. And when they arrived, this instead of X, they don't have to write a comment stating that this is the affairs student name goes. It's sort of the written in the variable name listening. Then it'll. The suit on this is called a self documenting code because we are naming everything in reference to how we are going to use inside or code so we don't have to write comments to explain everything. Same thing goes for functions on for any other thing. There is nothing wrong with self documenting court, but never hesitate to use comments in an before Toby, as expressed as possible about your thoughts on intentions. The purpose off a block of court may be clear to you if you wrote it 10 minutes ago, but I hear from now I will place. Comment may be as helpful to you as it is toe. Other programmers who are seeing girl called for the first time because one years means outscores has bulletin on. Do you are most likely, Let's say, lost in, according on When you see a code that you did write a year ago, you won't recognize it, and you have to understand it. Line by line. So I didn't want for men can make a little difference and save you a lot of time. Some people use comments to document the date on time, so I will find them writing this. Let's say that today is John 2020 aunt. It's 9 30 and last. It's now this one. Make sure that you have are clear date because sometimes when you could be a file from one location to another location, it takes that time and date of the new location. So to make sure that your code has the last edit tag, make sure to update this when you eat it. Your coat. That's it for this lesson. Thanks. Washing. This is Ashraf. 7. 7 Reading keyboard input: Hello and welcome to this annual Asan in which are going to explain how to read. Keep orb inputs for reading input from the keyboard. Parton provide the input function in poetry is what they use our types on the keyboard and returns it as a string, and you have to concentrate on this line. Python. Will it end? Whatever you right, the keyboard or using the keyboard as US shrink. Now here's an example that combines input on print functions to capture a person's name on displayed on the screen. We start by defining a variable school it name on a flight in port. Now, inside the airboat, you would write whatever you want to be. Disability they use are under screen. We will ask the user to enter his name. Enter your name. Now, when he enters his name, the input function will take it and start inside the name variable. After that, we need to print the name using the print function. Now let's run the code, Jay. Let's make sure that are running the right file. She's read in boat. Okay, now it's asking me to enter my name. My name is Asher off now. It did then, Ashraf, as you can see here in this line now the string passed on out or as an argument to the input function is the probable that your user will see in this example you are asking the user to type his or her name. Enter your name. Hey, if between these two single politician you can share this with any other thing. Once they use those types a name on press's winter very boat function would tell the name on Store it inside the variable the function with detail The value, which is a text here on the text, will be assigned to the variable named Blame which is here. That invariable is then used as an input or argument toe. The function, print and print will plant the name that was written by the user. Now you can all school the input function without a perimeter. You can simply write it like this. Let's come in these two. You can simply do this. You can write print on between these two you can right enter or what is You're the name. And here car right name equals and vote. Then you can plant the name now if we did problem. As you can see, what is your name? Which is this line? I would like to Ashinoff. And as you can see, it did plant my name, which is Russia. Now. This program will behave almost the same as the 1st 1 The difference is that print by default adds a new line to the output. So in the previous example, we have the name written beside. So what's your name lying while in this example? When we called in boat, it added a new line. So we wrote the name on a new line. Then it's print out the name on a new life. As you can see here we have three lines. Now frequent these three and remove the comment from these two. Once you right here, you will start writing at the very same darling as you can see and when you press enter, it will print your name in the second line. It's not the case with this example. This will be printed on a new line. On this will be added a new line. We will add your name when you lying because input adds a new line on then the name will be printed on a new line. As you can see you, it's not a very big difference, but this is, or this is how you can take an input from the user using two methods, not just one. You can either pass a variable or a value inside the input value or then, but purposes. Or you can leave it empty on Asked. They use that in a separated line to enter his name. Now, if you want to read numbers as input, the input function always returned the type value as a string or text on. We already Ah, we have seen this in this example. This makes sense because they use our can enter whatever value they like. Even if the in vote is a valid number, it's stand returned as a string type from the input function. For example, if we did ask the user to entire a number and here and let's make it X now, this called, as you can see here, will print the value that they are entitled on. We want to print the type how the other dimension that I function now the tide will return the type of variable X. Let's run the code. As you can see, If I wrote five, it did print five on the type. All the last type is think it's not a number because we're a dimension that the import returns on Lee String value. No running this code on entering the value five would display sprink, which is this one. This makes sense because the usar entered a number but tha function retails a text even though the value itself is on is numeric To tell the value in tow a true inter valuable you can use the end function on to use the end function. We have to do this. As you can see here we are using the input function and we're asking their they use are to enter a number we cannot here and which stands for integer on. We can add to parentheses. Now the in function will call the in but function on will kill those after inter number. Now this will Ritter. A string on this string will be converted to integer and will be stored beside the X variable. So this in function will converts thing toe into judge and store it as an integer in the X variable. No, this God will output class and let's try it out. As you can see, let's like five. As you can see here we have the class interchange, which means that this numbers now on Intisar on X variable is an integer. You can use the float function in the same way. If you expect a fractional Kim Bolan, you can simply right float here. Andi, when you run the code, you can send the right one. Okay, that's him right here. 1.5. And as you can see that that a type is float so flawed variable here or float function takes the strength in boat from the user, aren't converted to float, then store it in the X variable as a float. So the type functionality and float as you can see here. You know, there is a very important thing that I need to mention here. If the in book isn't numeric and you pass it to the inter your function, as you might expect, this would be an error on because a runtime failures the program will end. At this statement, you can try it out yourself in the by phone interactive concern. Andi, let's run this cold on. Let's enter a A is basically a character. It's not a number. So if I click enter as you can see, we have a runtime error. Could not convert a string toe afloat because this is not around about this character. Okay, so this is called a run time enough. Now let's talk about another thing which is converting numbers to strength. You can go the other direction as well. The string operation will take on into your or float value on tear it. Interesting. This is required. If you are on captain ating the number into a string, for example, you can light X equals five. Now we want to print this line, though number is Los X. Now if we print exe, let's see this. As you can see, we have a problem. We are all trying to contaminate a string with an integer, which is wrong now, to make sure that we are able to bring this into sharp beside this line on concatenation them, we need to use the string or str function. Now str function will take this into jar unconverted to string, then concoct innate this string, which is five with the number is on now when we print it out, As you can see, the number is five. So what this will do is basically by this, uh, number is five now, five. Here is a string because we use the string function to convert the integer here between these two parentheses to string this is the only way that you can print or contaminate a string with a number. That's it for this lesson. If you have any question regarding anything, I'm here to help you. Thanks for rushing. This is actual from 8. 8 Exercise Build a program to say Hello: Helen will come The sinuous on Now, let's use what you learned about print input on string concatenation to display a personalized greeting using a bicycle script. Now, the first thing that you need to do is basically create on your file piles new python file on. Let's call it Say hi. Yeah. Now click. Enter on. Now you have on your python file. Let's start by. Printing will come. Okay. Can print using single Okay will come now. The next thing that we need to do is we need to ask the user for his name, so name will equal input enter a few of name then we need to plant his name. So we will plant this. Hello? Coma then leave a space then you can't like the valuable name Now we planted will come. We asked those often tell his name. He will enter his name and will be stored as a string inside the name variable on. We can concoct any the hello string with the name string on printed on our screen. Now what you need to do is simple. You need toe Ron and make sure that you are running the right file. Say Hi. Now will come into your name. My name is Ashinoff, As you can see here. Hello, Russia. Now we can prove this program. We can ask the user for his age and cuff, you've is sorry. Okay, Until you is No. We can enter your pay. Three. We can ask him to until his birth year on. Do some math. Now. If he did enter his birth year, we can create a new question here. Let's cover this to into shirt using the end function that we already mentioned. Until you have has changed this the birth year now is equal 2020 which is this year minus pair. Fear No, we can't print here. Your age is we can tell him his age blasts is now. If we print age, we will get an error. Why is that? Because age is an interjection on. In order to print it out, we need to convert it to string using the S t R function to make sure that we can't detonate strings together. Now let's just this out. Koran Say hi. My name is national. My best years. 1989. No. Hello, Ashraf. Your age is 31 Okay. Now, as you can see, we used a mathematical operation to calculate the age. We took it as a string converted to integer. Then we used it in an equation. Then we converted back to string in order to can Captain ate it with this line. Now, this is a very symbol exercise that includes everything we have covered so far. You should try it out on once you're done with this, you are good to go to the next exercise. Thanks for watching this lesson. If you have any question, please ask in the q and a board. 9. 9 Exercise Build a simple calculator app: Hello and welcome. Now let's try with other exercise toe build a symbol calculator. App. Now that you have experimented with reading input and creating variables, let's write a slightly more complicated by phone program. A symbol additive calculator. Let's start by creating a new python script file named Calculator. Go up here. Click file. New vital file. Come then present. Now we have this new file in the script file. We need to write the following program. First, we need to ask the user to enter the first number. Andi, let's assign into the variable named X so X equals input. Enter first. No, no, Let's ask him to enter the second number and store it in the variable called y input. Been tough Second mom off. Okay, so me Now we need to add the two numbers together on assign the result toe a variable name . The result no result will equal X plus y. Did we forget something here? I will give you five seconds to guess what we have missed in this court. Okay, Now what we have missed in this coat is converting these things as we know and boater turns as string. We convert this string toe into your and store it in an interval or valuable. So we need to write end on. We need to run at two parentheses here. When it's light and on, we need toe to parentheses. Now, what we need to do is just this out on. We need to print the results. Rent result now, Ron. Ron, say hi. Okay. No fun. The calculator app until the first number five. The second number six. Now the result is 11. This is it. You can add a few comments you can't hear moment. This is the first number. This is the second number. Andi, this is that is off. Just to make sure that we use everything that we have learned in this crash course now. Ah, this is it. This is how easy it is to create a symbol, calculate or ab that can add two numbers together on what you need to do at this point is create a program like this. We can adjust the result. We can print a line saying that the result off something picks plus X Blust. Last sign. I would expect in a second on Why, Plus, here we can equal lost. Now this will bring the result off something X which is the first number. It will add the first number here, Blas, the second number, which is why equals it will print equal on from the result. Now the result is a number here, so we need to convert to string. You think using the string function on X Here is also a number. Why is also number? So we need to use the string function. Tokcan Captain ate it and we would explain why we are doing this now click Ron Ron five plus six on the result of something. Five Blast six equals 11. That's it. Now you can do the same for the multiplication. Let me adjust this. We cannot. Some you want some result We can add sump result on the handle the same x minus y we cannot mall duplication result. It's the soon X month blood bye bye have become onside div result Thanks divided by way now to bring thes lines, we need to the same thing. We can go with this line on Tom shares this with these four valuables, you know, some subtract multiplication division and he really to change the signs. Remind us. Monster application. Okay, now Lister style to see if it works. Done. Five. Five. Okay, As you can see, five plus five equals. Five plus five equals 10 5 minus five equals 05 months. About five equals 25 on five. Divided by five equals one. And you need to change this thing. We can remove the something that's players can see here. There's under five plus five equals 10. That's it. This is a very simple calculator in which we have implemented everything we have taken so far. Now, if you have any question, I'm here to help you. Thanks for rushing this lesson. This is actually from 10. 10 Conditional Statement: hello and will come from this new, less one. No child going to talk about conditional if statements using the if statement is a vital part of building virtually any meaningful program. You can use it to automate complicated decisions so that it can be applied repeatedly on consistently to your user input or data. When you use the tail called logic all decision logic, we are referring to our ability toe imbue our program with the ability to make a decision based on imports. Based on the decision, we can instruct the powerful interpreter to run some port on Skip off our other port. Now we're going to learn how to do this using F statement on who will use the if statement . Adam with optional is if statement no, a polio expression is any court that returns a bullion value. Onda bullion value is either through or force, and we already covered that. No, it's bullion is at dedicated data type and pie. Phone Andi. It's very important for if statements no, let's try accords where we basically ask if the value equals seven. Then print several right click the intro to buy full file, create new vice on file on Name it. If else this. Now let's go and enter presentation Woods Now here we can assign a value on. We can give it seven now to use if statement Basically what you need to write is simply like if then applied the condition. Now the condition is value equals seven. You know, if this condition is true, we need to do the following Going to print. The value is so once we are done, we can go back on rent finished? No, As you can see, we added print inside the if statement while this print is outside left statement. Now, if we added this print here, this means that this will only be printed if this condition is met. So if this condition is through, these two lines would be printed. Otherwise nothing will be printed now to see this in action, Click loan, as you can see. So this condition is through. The value is several, which is the fair sentence and finished, which is the second sentence are printed. If I change this to AIDS, let's run it again. As you can see, nothing is Brent it now to make sure that this is printed, even if the condition isn't true. We need to get out off this if statement, by removing these spaces all ending no from since the condition isn't true. Fist Lion wasn't executed while this line was executed because it's not linked to this if statement. So it did. Print finished. Now again, we went back on. Make it through. The value is seven. That's it. No, if is the key word TV. The boarding an exhibition is this one we have that will not see if on this colon character is required after the Boolean expression, so make sure you are not missing this one p Now what comes next is just as important. The next line must contain a code block that Ron's If the Boolean expression evaluates to true Inp iPhone. Accord Block is defined by using indentation, which is basically the spaces before the line. In this case, we used the tab key toe insert for individual cases, So each time I press this Ishara Place stab, it will add for on 234 four spaces on these four spaces will help the if statement know which lines to execute. If the condition is true, This indentation tells the Python interpreter that this court bolos toe the if statement up here on should run Will the bullion exhibition evaluates to true? If the Boolean expression valuers to falls, all of the indent or indented should ah be ignored by the Python interpreter. When you run the court, you should see the following output the value of seven, then finished. Now again, you can't change the value and see if the condition is false. What will happen? No. Let's update the cord example to include on instating. The else statement is on optional part off an if statement that can handle opposite case. In other words, when the bullion exhibition in the if statement evaluate Stow Falls run the cold block that belongs to the hills. Statement invested. Now let's update our code too much the ills statement. So after the if the bullet an expression, then this will be executed. If it waas true pins and at the colon. Then again plant. The value is not seven. Now let's test it out. The value of seven now off, which aired this to eight. As you can see, the value is not seven, which is they'll statement Now This condition is isn't true, so this line won't be executed on it will execute whatever we have, the else part of the code. So what we have here is the value is not seven. As you can see here, the value is not seven. That's it. Now we can also update our code toe, include though else, if statement the ills if statement or rather, E if I will show you this in a minute is another optional statement that can be added below on if statements you can use the else if statement to test another related bullion exhibition. If that bullion exhibition evaluates to true the indented called below that kills if we're wrong, all called blocks that belongs to other if else if on in statements are ignored now to make sure that you understand it, let's use it. Let's play at else F statement here l if no, you need to add the condition are poorly an expression here on do you need to other life now, As you can see, we have missed the colon here we must add it. No, just like the if statement the ills. If statement must begin with else if it must include a Polian expression unlike the else statement Now it must determine it by using a cologne. As you can see here. Without it, it was show on the road on just as before. All indented code below the ills. If is part off the court block that runs If the bullion exhibition evaluates to true When you run the cords you will see that that ends If statement was executed because this condition is true now the value is eight unfinished. It didn't execute this one or this one because this is false on the else statement Is Onley executed? If these two conditions are false No, again we can add more else If statements here we can't print the value is nine Andi which aired this the line on drawn As you can see, the value is line. If we changed it to 10 since we don't have to in here, it will execute this one the ills because none of these is through. That's it. This is how you can use that if ills. If on else statement the conditional explicit mints No, there is also something that is gold nested if now listed. F means when you add to If together just this out. We can try this one if value or if you're on the shelf. If a new condition is through, then we need toe use another. If value equals seven, let's use this line. No, as you can see, here we have on it'll Marisol difference, which is new condition because we haven't created this variable. So let's create it. No, the value value is or equals. Let's say 20 friend 20. Okay, now let's this this out. Now, as you can see here, the value is 10. So nothing was printed, so this shows it 20. As you can see, the value is 20 was executed. No, this was executed because the first if statement is true now. If I chaired the new condition to falls and started to run the cords, you won't see the value is 20 because the first condition is false. On this Polian exhibition is false, so it won't go on. Check the misted f or the internal if statement. So this is like a double. If if the first condition or the big lie bigger condition is through. Go on chick the conditions inside it. Otherwise, don't go on our case. It's not true. So it won't check that in our if statement on this case is called listed. If statement on its widely used and programming and it's basically a double F statement if the 1st 1 is through, Go on, check the 2nd 1 Otherwise exit the program. That's it for the if statement. If you have any questions, please ask Infected on their board. I'm here to help you. This is Astra from 11. 11 Loops For Loop: Helen will come to the sinuous one in which I'm going to explain loops now. Loops and by phone are basically wave are ways to do primitive commands or repeating statements. Now Powerful has to primitive rope commands while loops on four loops. Now let's get started on programming. Languages need way off doing similar things. Money Times This is called iteration. Now it comes toe. For lube. The four statement is usedto. I trade over the elements of a sequence it's traditional, used when you have a peace of God, which you want to repeat in number off time. The photo was often recognized by on expressed loop, counter or no variable. You will understand this by an example. First fight fourth, no right counter and you can choose the ridge. So let's say that we want to start the counter and this range between one and six on. We want to print that count. No unique to other cologne here after the first line, and here you can easily print the count. Let's just this out, as you can see. When we did around this, it printed the number phone numbers from 1 to 5. No, you can also drive the four loop like this, and we'll give you the same result. You can't write numbers. The range controls the ranch function that takes to input from 1 to 6. Andi, you can live the for loop for count and numbers plans come. It will plant the same thing as you can see from 1 to 5 and again from 1 to 5. So these are two different ways to use for move. Andi. You can give this easily. Here we have. The Lube variable, which is the counter for new, is basically used for ICT racial over sequence that is either a list, a tobel, a dictionary, a set or even a string. This is list like the four Key Word and other programming languages on works more like on I Trait or My Food as found in other object oriented programming languages. With the for loop, we can execute a set off statements each for each item in a list to pull asset or even are really so. For an example, we can create a new are they? Let's call it foods on. Let's give it some valuables, couple Madonna on and sure no toe bring thes items we can easy right for X and fruits, different picks. So you can Who in this line? By adding the hashtag sign on drunk. Okay, you would have a problem. Okay, literal. These Okay. Now, as you can see, we have up in banana and chili. Well, child, the elements of this hardly. We have also these numbers which are elements of these ranch executed function. A four loop doesn't require on index invaluable. To sit beforehand or what you need to tow is simply started by selecting the variable of allocation or things you want Teoh read or to print or to deal with. On Dhere, you can write whatever you want. No. Even strings are trouble objects. They contain a sequence of characters and you can easily print them using loops. So for X L Let's say banana. We can't print X no free along the cold. As you can see, we have be a on a on a No, that's it's This is how easy it is to use the force. Luke to read isolation. Now there is something called the break statement with the brake statement. We can stop the loop before it has looped through all the items on. For example, we can take this sold meat. Andi inside this for we can add on if statement if X equals manana special, that's is in the same. Then simply break on by breaking. We are telling the for Luke to stop executing here so it won't print cherry Now if we did run this cords, as you can see, the last four Loeb printed a bill on a rented banana on one spin on it was printed. Ah, there is an if statement that checked If that printed X which is banana in that case, equals banana. So this condition is true. Then break break means get out off this four lube on Don't continue execution. That's why we don't have chair here. Printed after banana, this is the main goal off the break statement. Now again, you can exit the Ruben X is banana. But this time the break can be placed before the print. So if we place this if statement here, you can imagine what will happen. Our last example apple and banana were printed but this example Onley apple will be printed because once X equals banana, you will check if X equals banana. If this condition is through, then break. Don't plant banana. So no. In this case, as you can see here, only apple is branded. So the location of the if statement makes a lot of different or out of difference and execution. And since we are placing it for the printing statement, once the condition is through, it will break and we'll get out of the four load before printing who, though x value, which is banana. Now again, who blazed it back after the print statement, we will get the banana printed here. As you can see now, we also have another thing that's called continue statement with a continue statement, we can stop the current iteration of the loop aunt, continue with the next. Now, to understand this, we can simply use this very same calls. Blaze this if statement before the print under sort of brake light continue. No, What will happen here is basically it will continue their execution. If this condition is true, Aunt will skip the current iteration. Now, let me show you this. As you can see, it did Brent apple on sharing It didn't print banana. Why is that because we have continuing it now, when X equals banana on this condition is through that continue here was executed and continue here means go back the four lube on execute the next one. Skip the rest of the cord inside our four loop so the courts kept the print on. It didn't print panel. As you can see here, Apple and Cherry were printed again. The continue statement. Stop the current iteration of the loop and continue with the next iteration. So it's like a skip statement for the current iteration. No, we have other things that can be treated. We already introduced the range function on the rich function returns a sequence off numbers starting from zero by default. Andi equipments by one. Andi ends at a specified number. So if we added one number inside this, let's sit in clicked strong as you can see softly with zero on went all the way to line. Here it comes in more than one shape so you can use the ridge function on Dad to values from 10. Let's say 20 and when you Rhonda cord, you will see that it started with thin. Andi ended with 19. It can even take three values. So it's up to you. Another thing that you can do with four loops is yours. The else statement. The else keyword in a for loop lube specifies a block off court to be executed when the job is finished. So when this loop is finished, we can ad else here, uh, plant finally finished. Now, when this for Luke is executed, once it's done, it will plant the else statement, as you can see, finally finished. Now there's something else that's going, uh, misted lobes. And I said, Loeb is a lobe inside a little black. If statements, the internal will be executed one time for each iteration off the outer loop on to try this out. We can use this very same example here. Onda. We can add objective here now that I see decide some items threads big tasty on here. We can't rule this. We can add rental for lube inside this for Luke. So for why and fruits on four X and objective, we need to want this Sprint X going tohave the column here. Now let's see the results as you can see what happens here. It did plant red Big Tasty because we only selected X wind, Select ex and why to bring them together, as you can see, did Apple, which is X rated apple fed banana red cheer, Big Upper, Big Banana on big, cheery, tasty apple, their step alone and destitute. So it will take each of the exes on glue the wives so it will take the red. The loop. Apple Planetary will take big on Globe Apple Penology on Dent will take Tasty and Loeb Apple Planetary. That's it. This is how to deal with four loops on. This is basically everything you need to know about four loops. There is still more, but this is all the basic stuff that you need to know about four loops and how to use them in your recording. Thanks for watching this. Listen, if you have any questions, please ask in the Q and a board 12. 12 Loops While Loop: Helen will come the sinuous on which we are going toe talk about Why loops with y lube. We can execute a set off a statement as long as a condition is through. Um, to test this out, let's create a new python file. Score with wine tastes No, create a new variable. Let's make it r equals one now Why then you have to either condition. Let's say I is below six. Then add a column print. I now I equals are blessed one. Or if you can write it this way, I Blust equal one. Now let's explain what's going on here Now we create their new variable, we call it. I give it one as initial variable of value on this is the condition. If I is blow sex, keep doing this. What will do here is we'll print that I value, which is basically one to begin with. Then it will increase the I buy one. So the next time this while Loeb is executed, it will shake. If two is below six on this condition is true, it will print to Then it will increase it. I will become three on it will go back to check if three is below six, which is true, it will bring three until increase the value by one. So I will become four. It will go up here is for was four below six or not? It is. It will print for again five Blow sex. Yes, on when it is sex is sex below six. No, sort one print sex. Now let's run this cold. As you can see. One, 2345 Now we can't shares this and make it thirsty and run the court again. As you can see from one toe 29 If you want to bring 30 we can add below or equal as a condition on now. As you can see, we have 30 because we added equal. If you want to print our to increase the value off I buy to, you can change this to to instead of 123 it will the 1357 9 11 13 15 17 19 and so on. You can change this with five on again. It will be 16 11 16 and so on. No, the wind blew Requires relevant variables to be ready andan all example we used by on we sit it toe on initial value off one we can use break statement inside our Why lube on to do this? We can simply at the condition. If I equals three then break break will in this wild loop if this condition is through. So let's share this the one Now let's run discord. As you can see. 123 Once this condition is true once r equals three it will break this wild lobe on Get out of it now. We also have a continue statement that can be used. No. With a continue statement, we can stop the current iteration off. Why? Loop on? Continue with the next iteration. So if we did run discord as you can see, if I equals three, it will continue. So it will go up here on that one. Increase our by one. This is why you are stuck in three. Have now tow. Avoid this. We can change the location off that increment, it appears, and as you can see here we have it right now. 1234 And as you can see, one wasn't printed because we have the frontier. Can't change it to here. No, let's do this. Okay, now, too. As you can see, we don't have three hate. It's not printed because when R equals three continue, continue means ignore the rest off this cold on, go to the next iteration on. This is the main goal of continue with the continue statement, we stop the current iteration at this line. We didn't execute this line on. We continued the next iteration. That's it. This is the more the Ringgold from using that continue statement on. There's also an else statement that we can use to run a block court once the condition no longer true or once, once we finish the while loop. To do this, we can simply right here girls different. Done. No. How's it going to see? Once it's done, I could come off this here once it's done from 1 to 5. Then it will print down, which is inside the l statement. No, this is it. This is everything you need to know about the why Lou. There's also something called misted. While where you can add to why loops together just like the four loop on you can even ah create while on four lube in the same script, depending new needs. Both of thes will repeat the cord inside them until the condition is true. But while is more is more like, Ah, for repetitive tasks. Andi, you can easily other condition. While for robe you can't easily add a condition, you have, ah, to stick to the iteration for less string at Ray's on I Love Stuff. That's it for this lesson. If you have any questions, please ask in the Q and A aboard. This is Ashraf. 13. 13 Exercise UserName and Password: Helen we come this annual Asan, which are going to apply what we have learned in the previous sections. Now we are going to create a program that asks that they use us to enter his user name and password. So let's get started. Use that mean, let's say that there's a name is Ashinoff on the past World is 123446 No tow us there to enter the password. We need to use the input function in Turkey Your name on and toe. Ask him to enter his password with you. We need to use the input function. You'll bus hand. You need to ask for his user name now. Once he enter his name, we need to store it inside a valuable let's call it users on the past, full inside of arable. Let's call it pass. No, to make sure that what he entered is correct. We need to use the F statements. Onda. We can start by writing if users equal users name. So if the first condition is through, we can. As for the or chicken, the password is through. So if pass world equals the past W, then we can plant blue thing? No, we have to add double equal sign here and here. Andi, if there's our name and password are true, it will print. Welcome. Otherwise, those we need to print vassals. Okay, now let's just this out a of our own. They use that pass. Not until there's a name. It's Ashinoff. The password is 123446 Now did Print will come. Let's try to enter them. Grow past solved. Now what if we entered along User name. We need to run it again. As you can see, when we enter a wrong user name, it asks us for a password, which is not true on we should change this. We need to make sure that every user name is wrong. If these are name is not correct, we don't want toe until this area on. Check the password. Okay. And to do that what we need to do if there's a name is through interrupt this area otherwise used else different the wrong. Use our name. Now let's this this out. Okay? As you can see wrong user name. Because the user name that we just entered is not correct. No to change this order or the order of thes two ministers. We need to move these two lines now. First willing to ask the user to enter his name or user name on. If there's our name is correct, then we can ask him to enter his bastard. Now that the password is correct, we can print will come. Otherwise we can't plant strong passwords. Now these are name isn't correct. We can go to the ills on plan Throng. User name? No. They say that we have our own views are name. As you can see, your user name on the program ended.