Python Programming Basics: How to go from Beginner to Pro | Connor Look | Skillshare

Python Programming Basics: How to go from Beginner to Pro

Connor Look, Tech Guide, Entrepreneur

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
18 Lessons (34m)
    • 1. Introduction

      1:04
    • 2. Installing Python

      1:51
    • 3. Printing text

      0:59
    • 4. Creating variables

      0:29
    • 5. Printing variables

      0:33
    • 6. Implementing variables into strings

      0:58
    • 7. Assigning the user's input to a variable

      1:58
    • 8. If and Else statements

      2:17
    • 9. While loops

      2:19
    • 10. Converting texts

      2:06
    • 11. Annotating

      2:04
    • 12. Creating lists

      1:03
    • 13. Random module

      2:07
    • 14. Time module

      1:30
    • 15. Len function

      1:45
    • 16. Int/float input

      6:38
    • 17. Mathematical operations

      3:50
    • 18. Project - Apply your knowledge

      0:54
19 students are watching this class

About This Class

Continue your learning: Python Programming (Third Edition) (For the Absolute Beginner)

Welcome to my course. I am Connor, and in the next 34 minutes I will take you from a beginner at Python Programming and teach you all the skills required to begin coding your own programs. This course includes the knowledge of a 2 year GCSE Computer Science course in a fraction of the time. By combining everything I teach you in this course, you'll be able to code an endless array of fun and useful programs.  

You will learn:

  • Installing Python (python.org)
  • Printing text
  • Creating variables
  • Printing variables
  • Implementing variables into your strings
  • Assigning the user's input to a variable
  • Using If and Else statements
  • Using While loops
  • Converting texts
  • Annotating your code
  • Creating lists
  • Using the Random module
  • Using the Time module
  • Using the len function
  • Taking an int/float input (Including handling Type errors)
  • Performing mathematical operations 

Lets get started

a134898f

Transcripts

1. Introduction: Welcome to my course. I'm gonna be teaching you the basics of Peiffer. By the end of this course, you will know how to install python print text, create variables, print variables, implement variables in jail strings, signed the uses, input to a variable use. If else statements use war loops, convert texts, annotate your code, create lists, use the random module, use the time module, used the land function, taken input and cast it as an integer or float number and perform mathematical operations by combining everything and teacher in this course, you be able to code an endless number of fun and useful programs. This course will bring you up to speed with a program, the aspect of a computer science GCSE so let's get started. 2. Installing Python: Pipin is a free and secure programming software that you can download in his store easily from online. If you've already got piping installed and are ready to start cloning, be sure to skip to the next video. Let's get started by opening a new tab in your browser and searching for poison. Don't go. Once the pages load it. We want to go to the downloads page. From here you see a button which allows you to download the latest version of python for your operating system. Currently, this is 3.7 point four for Windows. If you want to select an older version, you could scroll down. But I'm going to choose the latest. So we click this bottom, it will ask us to save it. I'm going to save it to downloads. As you could see up here, it shows the progress off its download. Now that is finished. We could run it. It will come up with this set up page asking us what we want to do. So I'm going to click and life in 3.72 path Andi install now. As it says here, the set up was successful, so we can close this minimize all browser, and then we're going to want to go to our Mac or Windows Explorer and search for quite. We want to select Python Idol. It will open with the shell. We go file, you file, and now we're ready to stop coding. 3. Printing text: printing texting pie often simply means writing it to get started. We're going to print hello world To do this, we type print open brackets, Speech marks, close brackets. Hello World to run this we press f five or go to the run and click run module is gonna ask us to save its press. OK, now I'm going to save this here as world. If we save that, you can see that it is printed. Hello world. What we're printing here is called a string, which is what text in python is called. The string is defined by having quotation marks around it. 4. Creating variables: to create or define a variable, we must first choose a name for it. We then put on equals and what value we want to be assigned to a single equals assigns value. So, for example, if we put color equals red than the variable color is equal to read. 5. Printing variables: Now, if we want to print the variable color, we first have to define it like I showed you in the previous slide. So to do this, we're going to do the same. Color equals speech books. Bread Now to print nous, we're going to want to print open brackets, close brackets inside those brackets, put the variable color. So when we run this, you can see that it is printed red, which is the value of the variable color. 6. Implementing variables into strings: If you want to take this a step further, we can print the value of the variable with a string. To do this, we've use a comma or a plus. If we use a comma, it WADA space between the value of the variable and string with a plus Allowed it directly afterwards to print the variable color with a string. We're going to want to put Prince over brackets, close brackets inside speech marks We're going to want to put the color is and I'm going to put a comma so it adds a space between the string and the value of the variable color. So what scam We run this. As you could see, it is printed, the color is red. 7. Assigning the user's input to a variable: to give a variable of value that the user decides is done by taking an input. For example, we can do this by taking an input for the variable name by doing name equals input open brackets, close brackets Onda. We can put a preach before this asking What is your name Now? When we run this, you'll see Prince, what is your name? On the next line? It is taking the input and we can enjoy our name. We could do this a different way, which is? We remove the print and we can put the question within the brackets off the input. So we're just all schools in your name within these brackets. I like to add a space between the string of the question on the input so that what the user enters isn't right up against the question. Now we run this. As you could see, it works the same, but it stays on the same line. What is your name? I end my name and it takes the input off my name. So to demonstrate what it's taken, they can print the variable name. After this old there's my name and to include the previous lesson we can print. Welcome coma. Name Colin. This program. Now, this will print my name within the string of your name and my name says welcome corner to his program. 8. If and Else statements: we use if statements to test if something is true. If it is, the code is run. For instance, we can check if in answer to a quizzes, correct by testing the user's input against the correct answer, then to check for other possibilities. We type. LF, which is short for else, if another option we have is to use else. This means that in any other case, this code will be run to demonstrate this. I'm first going to take an answer from the user it's called Is Variable Cancer and make it equal to their input. Hold the question. The question among going awesome is what is the capital? Oh, friends. Once again, adding a space so that they're in the user's input is not right up against the printed text . Now to compare their answer to the correct answer I'm going to do if also, which is what their answer is. That which they input is equal to the correct answer, which I put in quotation marks because I'm taking a string input yours and then I put a colon and it will leave an indent which can also be done using shift and then we're going to want to preach correct on and tells which means in any other case, is abrade incorrect. So it was Paris. Now, if you run this, you'll be able to see that if we put in Paris it was a correct. And if we run it again and we put in London, it was a incorrect. The answer was Paris. A double equals compares the value of each side asking if the first side is equal to the second side. 9. While loops: whilst demons works similarly to if statements in the way that they test for if one value is equal to the other. However, instead of just running that code once while stemmers run the code while that statement is still true using the example above, we can demonstrate this instead of just testing to see if they use got the correct answer they're moving on. We contest to see if the user is correct, and if they're not, we've run us again. One of the simplest ways of using this is the set of variable to true or force we tested. It is still true force than run the code again at a point within the code. Say, if the user gets to correct answer the variable we switched, meaning that the code will no longer be looped. Now, if we want to use for war loop to ensure that they get the correct answer, we want to first define a variable which we're going to test for the Waldroup. So I'm going to name this very big loop and I'm gonna make it equal to for it so long Luke is leaving to true. We want to loop all of this and add an indent. All of this you select it and press tab, you're at an indent, which means all of this is within the war loop. So while the loops variable is equal to true, this will loop. Now we want to add inside if they get the crop plants correct is equal force. And if they don't, it's still just tells them that they're incorrect. Andi, it will loop again. So if we run this and then what is the Capital Frantz into Paris? And it says correct. And in the program, if we enter incorrectly and like the previous example into London is incorrect, the answer was Paris. What is the capital, France? It asks us again. Now, once again, if we get it correct, ends the program. 10. Converting texts: text in python buckled strings. So the words that are printed, our strings converting strings could be used for when we want to compare them in. If statements, for instance, if we haven't s statement that is asking the user a question where capitalization doesn't matter, that we may run into some issues when testing their answer against the desired answer. This is because if statements are case sensitive, meaning that it is important whether or not certain letters are upper or lower case to convert strings, we and even dot upper, which converts it into all uppercase dot lower, which converts a string to the lower case or capitalize, which makes the first letter the string a capital letter to demonstrate this using the converting texts. I'm going to change the question toe where capitalization doesn't matter, because with a place such as Paris, it does matter if you put a capital P because that is correct. So I'm going to change the question to want is the drink off G be of Great Britain? Andi, the answer for this is T I'm going to put this full uppercase because I'm going to convert their answer to follow case The reason I do this is because it doesn't matter whether they put it in upper or lower case. The answer is still T andi capitalization doesn't matter in this circumstance. Let's make sure we change this answer to T. Now we can run this. What is the drink of g B? We can put it, however, Capital T. It's correct all lower case. It's still correct. Once again, if we put the wrong answer, say coffee, it will say incorrect. The answer was t and ask us again. 11. Annotating: it is important Hannity a code as you go along so that you can understand what it does when you come back to it, or so that someone else can understand it. You do this by typing hashtag anything you type. After this will be notes that does not affect the coat. To resume the code, you simply start another line by pressing enter. This is very important and I cannot emphasize enough how valuable it is to annotate your code. Countless times I've come back to a piece of code to adjust it and have been unable to understand what it was doing. Now I'm going to demonstrate annotating this code, which I've shown you. Now I'm going to aunt before this. This defines the variables which in this case is just one. This is loop. So pollutes the code I like to put to just if it's a big chunk and then for more specific we're going to put one. This will take users inputs and then this. If statement, we'll check if their answer That's correct. If it is, if it is the blue I stopped. And in every or any other case it isn't. Andi here is outside outside of the Luke 12. Creating lists: creating a list is very similar to creating a variable, but instead we list things inside the brackets. For example, if we wanted to create a list of names and it, we could call the list names, then assigned the list of names to it, which we put in brackets separated by Commons. I'm going to create a list of names, so that's cool. The variable that list names make it equal to one name that say no on and we put a comma and then we put another name. If it's a string you're putting on a list, you need to put quotation marks around. It exploits Olivia and James. As you see each one of these are its own separate part of the list because their strings there, surrounded by quotation marks on this, separated by comments 13. Random module: if you want to incorporate some randomness into your code than the random module is a very useful tool. A module in puffin is sank that you import to get the random module, we first need to import it. So to do this, we type import random. I like to do this right at the top to keep it simple. Now I'm going to use the list of names to demonstrate this. So to choose one of the names I'm just gonna call this variable name is equal to random dot choice. So this is using the random module here, and then choice will choose from a list inside the brackets. I'm gonna put the list the name of the list, which is names. Now we can print the name that is chosen from the list. So if we run this as you could see, it shows Olivia run it again. It shows Noah I would drive to Gangsters and livia again. So it's completely random now, another way we you can use the random for module is to generate random numbers. So I'm gonna name this variable numb underscore one and make it equal to let's put these as notes so that leads do not interact. Norman's go on is equal to random thought brand. It's so random into then, inside the brackets we want to put the range, which I'm going to put between one and 10. Now, once again, I want to print is variable, sir. Inside the print Going to print the variable numb on the school one for wrongness because he chose 10 We're on it again shows eight Run it again it shows one. 14. Time module: the time module helps pace outre code when you run it. So instead of everything printing instantly, you can add a delay. The time of function is simple but very useful and effective. To use the time module, we wants again have to import it. You always have to important module, so we're going to import time now. I'm going to demonstrate this because what it does is advance delay between different aspects of your code. So I'm gonna add delays between Prince so we can print welcome time, not sleep. This is how you do it and do time for module dot sleep and delay. I'm going to do whatever is inside the brackets is how many seconds you can make this float number to keep it simple. I'm just gonna make it one second. Welcome to I think this course Now I'm going to copy and paste this control. See, control the and when we run this, you'll see that it prints welcome. One second to this course 15. Len function: the Len function in pie often is short for length. This function is used to measure the number of characters in variables or lists. Here's an example. Let's take an input from the user. I'm going to make the variable strict code string because input. Then we're going to also end anything once again adding a space so their input isn't right up against the printed text. Now, to print, you'll string is Coma and Len Inside the brackets, we put the name of strength. So what Len does is it counts the number of characters within their strength. And I'm going to put can no. So what this will do is lend. It will count how many characters are within here so you could define variable by making the length of a string is equal to lend And then the variable name. So we print nous we run it. Sorry and anything. I'm just gonna end Hello world. Your string is 11 characters long for counter. There's 123456789 10 and space counts as a character as well 16. Int/float input: int is short for integer, which means whole number afloat number in computer science means a number, which has a digit on both sides of the decimal point. What I mean by casting in the input is that after the impetus received, it is made to become an integer or afloat. Normally, when an impetus taken, it is presumed to be a string. But if we cast the input as a float or an integer, they will try to make what is imported into afloat or an interview. And I say trying because this is where some errors may occur. But I'll get to that later on to take an integer or float number input. We're going to start off by defining the variable in the same way. So I'm going to do number underscore. One is equal to input from the user. I'm going to Austin to enter a number, but what we do differently is we put in and we had a bracket there because there's two brackets on this side. We must add a never one from the other side to make it equal. Now, this would take an integer in boat so we can print this variable, not only school one, and then I'm going to print it using with mathematical functions, mathematical operations. So I'm going to add 10 onto it. So if we take the input and asked us, enter a number, I'm gonna enter 11. There were prints, 11 in a no print 11 plus 10 which is 21 now. If we try to run this Onda, we enter a word. Say no, Andi. It will come up with a value era because it's expecting an interview. It's trying to cause this as an interview number, but we entered a strength so it will crash program. I will show you in one second. Hell, you can get around this, but I would like to also note that this can be float number and then, if you aren't, if you're under an interjection, want zero on the end. And if you enter, floaty will accept it. Where's and interview only accepts whole numbers, which means you add afloat. We will come into the same problem with the value era now for something a little harder handling the errors. If you want to skip this part to move onto the next lesson, then that's okay, You may encounter some issues which could be resolved by what I'm about to teach you. You're noticed that if we enter a string when an integer is expected, we get an air of the pops up called a value era. To prevent our program from crashing, we can use the exception function. What this does is this allows the error toe happen. Now, of course, if we need a number for the rest of our program toe happen say we using the input to perform mathematical operations and we're going to want to use a while loop toe, make sure that we get the desired type of input to use. The exception rule is as follows. I I'm going to add Troy, Andi at Indian were pressing tab and then it will try that code box. As you saw if a value error comes up by them even ending afloat or string just the wrong kind off input and then we're going to want to accept the value era. And if a value of our era comes up going to want to print, please and, uh uh, into job now, if you run this, you'll see that he will ask you to enter a number as it previously did. I'm gonna enter five. It works fine. Prince five, Prince five plus 10. If we run this again and we entered the wrong kind of input say we type five words and it will ask us to please and interject to make sure that we get the right kind of implants. We're gonna want to put this inside a wall so Wall Luke is equal to true. We want this to happen now. Of course. We need to define the variable loop and make it true if they successfully get a correct. In a sense, if it works and then we're going to want to put loop in cool fools, this will mean that's the loop. Will The world loop will no longer loop. So it ask us, tend to room number. I'm going to end number five. It works fine. If we enter wrong kinds a 5.5, it was say please enter an integer and itwas cause again and throw in string a Ross's again until we enter an integer when it will accept it and move on. Another similar built in function is taking a string with a value that is a number and the signing it to another value as an integer. We do this by adding int, then putting the of a string in the brackets we can now, before mathematical operations, adding, subtracting, multiplying or dividing on this, this could be done the same with float. Of course, if you want to use afloat, you need to put float before the variable name, which is inside the brackets to be able to make this work. If you try and uses method to taken into or float input, then you also have to use the except function if the user inputs selling else. 17. Mathematical operations: As previously explained, mathematical operations are adding, subtracting, multiplying and dividing to demonstrate mathematical operations in Python, I'm going to first define two numbers, so I'm going to find some underscored. One is equal to seven on long underscore. Two is equal to 11. Now I'm going to print no school one plus I want to score two. Now I'm going to copy this and paste it free more times and change it so that the 1st 1 is a plus 2nd 1 minus for one. The times, which is the Asterix if you press shift eight and then the fourth is a divide, which is a forward slash. Now, if we run this, you'll see that it will display all of those numbers so added together, taken away, multiply together on divided for simplicity. I'm also going to print no Wonder School one, and I'm just going to buy themselves to show what they were originally, so you could see it seven and 11 and then added together. Makes 18 7 Take 11 is minus four. Multiply together 77 0.6 free. Recurring. Another mathematical operation that is available for you in python programming is the greater than or equal to signs. To demonstrate this, I'm going to create a quick countdown to make it practical and going to import time so I can add a delay. So let's make the countdown five seconds. Just defined the variable number two schools. One is equal to five, which will be our seconds in a second. Long number two school one is greater than zero. So while the variable number of school one is grace than zero, we will bring no school one and then we want to do know unless cool one minus equals. It means it takes away. What is that? Whatever is on the other side of the equals, You can also do this with plus equals So this war and one second But in this case, I want to be taking away one second. So after printing five, it will take away one which is what you make it equal to four and then it will print for so I'm going to have tons of sleep one second. If you want to make this a counts down to zero, you can do greater than or equal to, which means it will print at zero as well. Or if it's great to that, you were only print, it will stop at one. I will do great on equal to zero. There's, of course, works absolutely around, so it could be less than if you want a higher number. But in this case, I want to be doing greater than or equal to zero. If we run this, you'll see that Prince 54 free to 10 18. Project - Apply your knowledge: well done for getting for all of that material. I hope you learn some link. Be sure to go back and re watch the videos if you need to recap now for the project to consolidate your understanding, I want you to use everything I've taught you in this course, and I want you to create a quiz game in which two random numbers between one and 20 are generated. The user is asked for the some of those numbers. If they get it correct, they get a school. If they get it incorrect, they lose one of their free lives once they've lost all of their lives and their game is over at the end of the game, it tells them their school. Good luck, and I look forward to seeing your project. Be sure to ask for help if you need it. Don't forget to share this with your friends of families so they can enjoy it as well.