Programming for Beginners: 4 Essential Concepts in 20mn | Thomas Gervraud | Skillshare

Playback Speed


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

Programming for Beginners: 4 Essential Concepts in 20mn

teacher avatar Thomas Gervraud, Indie Game Developer

Watch this class and thousands more

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

Watch this class and thousands more

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

Lessons in This Class

5 Lessons (22m)
    • 1. Introduction

      1:32
    • 2. Variables

      4:50
    • 3. Functions

      5:13
    • 4. Conditions

      5:39
    • 5. Loops

      5:04
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

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

426

Students

--

Projects

About This Class

Curious about programming but don't know where to start? I made this class for you!

Do you want to go on a short (but exciting) journey inside the programming world? I've been coding games and websites for 4 years now. Today, I want to help you understand the fundamentals of my work.

This could be the beginning of a new path for you. Millions of people have found jobs, launched businesses, made apps and changed their lives thanks to code - and it all starts with learning the basics of programming. Which is what I'll teach you in the next 20 minutes.

By the end of this class, you'll have a good understanding of 4 essential programming concepts - using a simple and easy to follow visual approach!

These basic ideas are the foundation of any coding project. Here's exactly what you'll learn:

  • What variables are... and how to use them so you never have to remember your own age ever again!
  • How to recruit your own robot employees (a.k.a functions) and create a thriving little virtual business (a.k.a your program)
  • How to keep kids from sneaking into your festival using conditional statements
  • How to use loops to 100x your program's output - with only one line of code!

We'll be using a simple in-browser code editor called repl.it with the Python language - but you could also just follow along using pen and paper. The concepts are what matters here, not the syntax.

So, if you're up for the challenge... join the class! I'll see you there!

-Thomas

You can find out more about me on my YouTube channel and my personal website.

Learn more about the world of programming with these Skillshare classes.

Meet Your Teacher

Teacher Profile Image

Thomas Gervraud

Indie Game Developer

Teacher

Hello! I'm Thomas aka Blobfish, an indie game developer since late 2018.

I've made games called Space Gladiators and Lost Potato that you can find on Steam. I've also got a newsletter and a YouTube channel that you might want to check out.

I'm working on a series of Skillshare classes about programming, game development and the Godot game engine. Make sure to follow me here if you're interested in those.

Also feel free to send me a message on Twitter, Discord or by email if there's a specific subject you'd like me to make a class about and I'll take it into consideration!

See full profile

Class Ratings

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

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

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

Transcripts

1. Introduction: Hey, my name is Thomas. I'm an indie game developer. In the last two years, I've met some commercial games that I've published on this team gaming platform. Before that, there was also working as a web developer. And I've graduated with a master's degree in IT and business. It means that I have been coding for more than four years now. In this class, I want to give you a simple understanding of the basic concepts behind programming and some good mental models for how to think about it. If you decide to learn more afterwards, programming just means giving a computer some information and telling it what to do with it, to create things like websites, games, mobile applications, and more. We communicate with the computer through a language that's just zeros and ones. This is called binary codes, but it's very hard to understand for humans. So we created all the languages that are closer to english, that just Python, Java, or C, that we can write more easily and that are then converted to binary codes. All of these languages have different syntax, but they all share the same basic concepts. It's just like when French and English use different words to refer to the same thing. For example, Bear and ofs both refer to the same big furry animal. In today's class, we are going to learn those basic concepts that are common across every language. We'll use an online tool that allows you to cook directly within your browser, which is called rebelled, and will use, which is a very simple language to learn. So go to the link I put in the resources, and let's get started. 2. Variables: So first we need to learn about variables. Variables are the building blocks of a program, the alleles of boxes that contain some information. And you can put a label on them and give them a name so you can find them more easily later on. For example, we could create a variable named age that contains the number 24. Every year, we could tell the program to automatically increase the numeric contains by one. This way, every time we ask the program, what's my age, it will be able to answer with the correct age without us having to remember it. Variables can contain different types of information. Numbers, takes and more. A number without decimals, an integer. This is the type we use to store our age. A number with decimals is called float. That text is called a string. A switch that can be turned on or off is called a Boolean. We can use it to store a statement that can be answered by yes or no. For example, if someone has black hair, we create a box called black hair. And inside of it, we'll put yes or true in programming terms. There are many more variable types that we can use, but it's always the same concept. So now let's take a look at our code editor. The only parts that matter to us are this one, which is where we write our code. This one which will display our code. And this button, which is the run button, which we convert our Python code into binary code. There's also a setting that you might want to tweet before studying. If you don't want info boxes to keep popping up all the time like this. So go to Settings, scroll to the bottom, and disable Code Intelligence. Okay, so here's how we can create a variable in a program. We just have to read the name of the variable, then an equal sign, and then the value we want to give to the variable. So now we've created a box or a variable called age with a value of three. If we want the variable to be a string. And I have to put quotes like this and right, the value of the variable within those quotes. If we want the variable to be a Boolean, you can just write true or false like this. The name of the variable needs to be only one word. So we cannot have any spaces. But you can use underscores like this, or you can also use capital letters. So I'm going to put the name back to age and the value 23. Now that we have our variable, we can modify it as we want. For example, we could write h equals h plus one. This means we take our variable age, which is currently three, and we assign to it to devalue age, which is three plus one, which means our variable will now have a value of four. To verify this, we can write the following line of code. Print, then open the parenthesis. And between these parenthesis, write the name of a variable. This will display the value of a variable on the screen. So now click on the Run button. And we can see that it displays four, which means the value of our variable age is now for. Now it's time for the first challenge. You can do it in the code editor directly or simply on paper. Syntax is not that important. It's more about the concepts for now. So here's what you have to do. Imagine we have a person called John H 36 with brown hair. Create three variables that each contain one piece of information and display all of them on the screen. All right, so here's how we do that. First we create a variable called name that will contain the value John. Then we create a variable age, which will contain the value 3-6. And finally, the variable called brown hair, which you can write like this, all with a capital letter like this. And we will assign the value true to it. Naming variables correctly is very important so that we don't start to get lost once we have hundreds of them. And then what we have to do is to write three lines of code to display all of these variables. So write print, then opens a parenthesis and write the name of your variables inside of it. Let's start with name. Then on the next line, print age, and finally, print grown hair. Then we can run our code and we can see that it displays all of our variables. Print is what we call a function. And we're going to learn that concept in the next video. 3. Functions: A function is like an employee that has a very specific task. A task could be to calculate the distance between two points to control the behavior of a game character, or to display our variables to the screen, like we just did with the print function. As a programmer, you're the CEO of your own little business, which is your program. You have lot of data to manage, which are all your variables. And if you want to do something with all of that information, you will need the help of your employees. In the real world, employees have names like John or Brian in the program. And employee will have a name that sounds more like prints. Debug our display. But it's exactly the same principle. That's all we're doing in a program. We create a lot of boxes with information we need and we manage our employees to accomplish the goal of our business, whether it be creating a website, robots or again, sometimes to accomplish that task, we need to give an employee some information. For example, the task of a print function is to display a message on the screen. To do that, we need to give it information we want it to display, which is what we've done by writing the name of our variable between the parenthesis, the variables that we need to give a function so they can accomplish their tasks are called parameters or arguments of that function. Here we can say that our print function has one parameter or one argument. Print is a function that already exists and there are others like open or close, that we can use to open or close a file on a computer. But we can also create our own functions and define what they will do. To do that, we need to type the keyword def for define, and then the name of a function which will be tests. And then we open the parenthesis inside of which we will put the parameters of a function. For now, we'll leave it empty and we'll finish the line with a colon. Then when we go to the next line, you can notice there's a bit of space on the left of the line. This is called indentation and everything that will be indented so that we'll have a bit of space on the left will be within the function. So now if we write, for example, print five, whenever we call a function tests, it will display the value five to the screen. So we can try it by creating a new line of code and deleting the inhibition. So no space on the left, which means what we will write now will not be contained within the function. And then we can just call a function like this. And now when we run our code, it should display five. We could also write a function that does the sum of two numbers. So if we give it two parameters, a and b, and we can use the keyword return, which will be the value returned by a function. We can then write a plus B. And now when we call a function test, it will take two parameters that we give it and it will return their sum. So for example, if we give it 25, it should return seven. But it will not display anything since we haven't called print. So let's just put print before function, and we just print the results of function tests. And this should display on the screen. Here's the second challenge. Write a new function called display some that takes three parameters and that display there some on the screen. So first of all, we need to use the def keyword and write the name of a function, display some. Then we need to open the parenthesis and give it three parameters, a, b, and c. And then we finish the line with a colon. Then we go to the next line, which is indented. And then we can write directly, print a plus b plus c, which will display the sum of all three parameters directly to the screen. We can try it by calling a function like this with 123, which should display six. You could have done it a little bit differently by assigning the sum of those three parameters to another variable. For example, D, like this. And then simply displaying the variable d, which will give the same result. Now, what if we want to write a function that will tell us whether we are in the year 2050 or not. So that would return true if we are in the year 2050 and false otherwise. Or that we need to use a conditional statement, which is what we learn in the next video. 4. Conditions: Sometimes we need to know whether a certain condition is met before we can do something. For example, imagine you're organizing a little festival where you're serving some alcoholic beverages. And you need to check whether the attendance are old enough to drink before you can let them in your head. Whenever a person tries to enter, your mental process will go something like this. If this person is ordered and 21, I lead them in. If not, they'll stay outside. We can do the exact same thing in code. Let's say our age variable is the age of the person, the strength to come in. We can then write if age is above 21 and end the line with a colon and create a new line that's going to be indented. And inside of that statement, we are going to write print come in. So if the age variable has a value that's greater than 21, this line of code will display coming to the screen. But if age is lower than 21, nothing will happen. But we can also write a line of code that will control what will happen if this condition is false. To do that, add a new line, delete the indentation, and write the keyword else, and put a column. Go to the next line with some indentation because we are within the else statement. And now we'll print stay outside. If we run this code since the age of a person is currently 23, so message coming should be displayed on the screen. Now if we make our age three, the message stay outside will be displayed instead. There's a small issue because we are checking if age is strictly superior to 21. So if someone is exactly 21 years old, there still won't be able to come in. To fix that. We just need to add a little equal sign here, which basically means we check if the age is greater or equal to 21. And if that's the case, we let them in. We can even put all of this code inside of a function that we could call Jet Age with one parameter, which is the edge. And take this code and paste it inside of the function and makes sure the indentation is correct. This way, every time we have to check someone's age, we just have to write check age and give it the age of the person. And we'll be able to know whether they can come in or not. Now, what if we want it to display yet another message? If the person's age is below a certain number, like ten. To do that, we can replace the else keyword by a keyword called elif, which basically stands for else if. And then we can write another condition. For example, age is below ten. And if this condition is true, we'll just write our other message. For example, you are baby. So now our code, we'll check if the age is greater or equal than 21. If it's not, it's going to check if the age is less than ten. And we can complete our instructions by rewriting the else keyword, which will control what code will be executed if none of these two conditions are true. So we can print stay outside. And this will be the message displayed when the age is not above or equal to 21 and is not below ten. So for example, 15. We can also put multiple conditions in one line. For example, if we also want people that are older than 40 to stay outside, we can use the keyword and in this way and add another condition. For example, age is below 40. So now if we set our age to 65, I'll still have to stay outside. Only people between the ages of 2140. We'll be able to come in or festival. It's now time for the third challenge. Imagine that instead of alcoholic beverages were not serving milk, and we have new rules. Fall festival, we only accept people under the age of 12. We tell the people between ages 12, 18 included that they have to bring balloons. And we tell the people ordered an 18 to stay outside. Tweak the check age function to reflect the new rules. As usual, there are multiple ways to do it. Actually 1. First we can replace the first condition by age is below 12, replaced the second condition by age is below or equal to 18, and change the corresponding message to green balloons. And we can leave the third condition as 0s. This means if the person's age is below 12, they can come in. Else, if the age is below or equal to 18. But it's also greater than 12 because people that are under 12-years-old have already come in. They have to bring balloons. And if they are older than 18, they stay outside. Now, what if we need to check the age of three people will have to use a loop. And that's what we'll see in the next video. 5. Loops: Now imagine that there are three people waiting to enter your Festival, each with their own age. We could just create one variable for each person and color check age function for each of them. That works fine when we have only three people to check. But what if we had a 100 of them, then it becomes a manageable. Fortunately, there's a better way to do it, and it's by using loops. Loops allow us to repeat the same task as many times as we want, but only writing it one time. Anytime we need to repeat the same task multiple times in a row, but with only slight changes, will use a loop. Let's see what it looks like. No program. First, we change how we keep track of all ages. Instead of having three different variables that would each contain one age. We can create only one big variable that will contain all three. This will be a variable of type array. An array is just a collection of basic variables, but that we put in one place for simplicity, we can write it like this. Ages equals. Then open the brackets and put all of our ages separated by commas. Then if we want to access the number 18, we can just write ages and open the brackets. And 0. To access 45, we can write one instead of 0. And to access 52, we can write two instead of one. This is because programmers start counting from 0, not from one, like normal humans. Now without a loop, if we wanted to check all of these ages, we need to write something like this. Jake, age. Age is 0. And then two same thing for 12. Now, let us see how we can do this, but with a loop. First, I'm going to delete all of these things that we don't need anymore. And now we can write a new variable that we'll call i equals 0. Then we go to the next line and we write the keyword while i is below three, then we put a column and inside of that statement will write i equals i plus one. Makes sure that line is indented. And what we've done is we've created a loop that will run three times, because when we start, our i variable is equal to 0 and we run the loop as long as the value of i is below three. And every time we do a pass on the loop will increase the value of i by one, which means it will be 0, then one, then two, then three. And once it reaches four, will go out of the loop. So now we can write instructions within that loop. And even if we put in only one line of code, it will be run three times. Now, I recreated the check function that we made earlier. And if we write Jake age within our loop and we give it as an argument, ages of i. It will run this line of code three times. The first time it will check to age of the first element of the array, the second type, the second element, and the third time to third element. If we run this code, it will display the result for each of these ages. Loops are really useful and they are used all the time in programming. Here's the fourth and final challenge of this class. Write a loop that will display the following result, 02468101214. So I'm going to show you two ways to do the same thing. So the first way is to initialize our loop the same way as we did before with the i variable to 0. And then while I is below, you're going to change the three to 15, instead of adding one to. Every pass of the loop will add to and will print to the screen. Now if we run this code, we can see that it works. It displays all of the numbers we want. And there is another way to do it, which is that instead of running the loop while i is below 15, we run the loop while i is below eight and will display I multiplied by two. And we also need to add one to i every pass instead of two. But it means that i is set to 0 when we start. And then as long as i is below eight will display I, multiply it by two, and we'll add one to i every pass of the loop. If we run our code again, it displays two same thing. I hope this introduction to programming was helpful to you. That maybe it's spoke to literal interests to delve a little bit deeper into it. If you want to learn more from me, feel free to follow me on skill share, and I'll see you next time.