video

Lesson video

In progress...

Loading...

Hi, I'm Rebecca, your computing teacher, for Programming Part 1.

For this lesson, you're going to need a Repl.

it account.

Which you will need to ask your parent, or carers permission, in order to sign up for.

You also might want to have a pen and paper handy, to make any notes that you need to.

It'd be a good idea, as well, to remove as many distractions as possible, so that you can really focus in this lesson.

Once you've got all of that ready, we can begin.

In this lesson, you will describe the tools an IDE provides.

You'll use subroutines in programmes.

You'll define a sequence as instructions performed in order, with each executed in turn.

And you'll interpret error messages, define error-types and identify them in programmes.

Answer this question then to get started.

Why do we need translators in programming? Can you remember that from lesson one? Pause the video, while you think about that.

Let's take a look then.

Computers can only execute machine code, so, translators are required for executing the programmes that programmers write, in high-level languages.

We're going to be looking at Integrated Development Environments in this lesson.

IDEs were created to give programmers all the tools they needed, to write programmes in one place.

They allow you to write, run and debug code without having to switch programmes.

They were designed to make programming easier.

IDEs make it easier to write code because they provide useful tools, like syntax color-coding.

So, if you look there, you can see a basic text editor at the top, and then an IDE example underneath, where there's color-coding, to show the different types of commands that are happening there.

IDEs can also highlight important syntax structures, to remind you to include them.

So, you can see there on that bottom one, that the first bracket has started and the second bracket has been there and highlighted, to remind the user that they need to put that close bracket there.

They will often automatically indent code for you.

Python is very particular about indents, and you'll see that soon.

The IDE will remind you if it thinks an indent is required, by putting one in for you.

So, the top one again is a basic editor, with no indent there, and then the bottom one is in an IDE, where the indent has been placed there for you.

And they can auto-complete lines of code that are typically used.

And you can see that happening there.

In programming, the language specific code that you write in has its own syntax.

The syntax is unique to that programming language.

An IDE can point out any syntax errors that you have made.

This means that you can check them and fix them.

In Python, the IDE will call the interpreter to translate the code and allow you to run and test your programme.

This means that you can test your code, as you write your programme.

Without an IDE, you would have to write all of your programme in a basic text editor.

You would then need to switch programmes, to translate the code and test it.

An IDE helps programmers, because it bundles together these processes.

So, how many features of an IDE can you spot in this diagram? Pause the video while you have a look at that.

Excellent, right, let's take a look at the answer then.

So, you should have noticed that there were some syntax colouring there, syntax highlighting, automatic indents and syntax error-checking.

So, introducing your IDE.

Here's a demonstration of the IDE, that you will be using for this course.

So, let's go and take a look at Repl.

it.

This is Repl.

it then, and you can find Repl.

it by going to your search bar and typing in R-E-P-L dot I-T, and then you can set up a free account.

Now, you must make sure that you ask your parents, or carers permission, before you do this.

Once you've signed up, you'll be able to go to your home page, and this is where you would see any Replits that you have created.

Now, I'm going to create a new Python programme.

So, I'm going to go all the way over, to this plus sign over here, and I'm going to choose Python.

Now, because Python was the last programming language that I used, it appears at the top, but sometimes it's not there at the top, and you might need to scroll down to find it.

And you can also have a look at some of the other languages that you can use, to programming in Repl.

it as well, if you'd like to.

But I'm going to choose Python.

And what this does, is it tends to put a silly name for saving your work with.

Now, I don't want to give it a silly name, I want to get in the habit of saving everything with a really sensible name.

So, I'm going to put my first programme.

Because this is going to be, your first programme that you'll ever make in Python.

So, my first programme.

That's what I'm going to call it.

Now, I'm happy with that name.

So, now I'm going to go to create repl, and then it takes it into a bit of time.

And it'll start going over into my environments.

This is my Integrated Development Environment for Python.

Now, I've got lots of different options here.

I like to have it on the dark setting.

So, if we go over to here, we've got settings, and I can click on there, and you can see there that theme at the moment, is set to dark.

But if you prefer to have it light, then you can change it to light, like that.

You've also got different font sizes to choose from.

Now, I like to have it huge, so that I can see it really well, but you might want to have it slightly smaller, it's completely up to you, but I'm going to keep it on huge.

Now, you probably won't want to change any other settings there.

You might want to change the side-by-side, to stacked, if you want to.

But again, I prefer it that way, so, I'm going to keep it that way, but, it's completely up to you.

Once you've got your settings right, you just click back on that top one, and that'll take you back to the main part.

Now, this is our development environment.

In this middle pane here, this is where I would type my code.

So, that is not Python code, but that's where I would type it.

And then over on the right-hand side, I've got where it will be executed.

So, any output or any instructions, that will happen for the user, will appear on this right-hand side and you'll see that work in a second.

So, I'm going to write my first programme.

My first programme is going to involve creating a subroutine, and I'm going to show you how to do this now.

So, I'm going to define a subroutine.

D-E-F allows me to define a new subroutine, so, that's why I've put that there.

And then I press the space, and I'm going to have a welcome message.

So, I'm going to call my subroutine, welcome.

So, def will define welcome, whoops, spell it correctly would be a good idea.

And then, I have to open bracket and close bracket.

And did you notice there, how I open my bracket, and then my IDE was really helpful and it put the close bracket right there, for me.

So, I've only typed the left bracket, let me just show you again.

And then the right bracket appears straight away, cause it's being helpful.

That's what IDEs are there for, they give you little clues and little tips.

Now, I also need to have a colon at the end of here.

Now, this is just syntax.

And when you start learning to programme in Python, you're going to make loads and loads of syntax errors and this is completely normal.

You are learning a totally new language.

So, don't worry if you forget the odd bracket, or the odd semi-colon here and there, because that is totally normal.

And I will be giving you syntax checklists, whenever I give you a programme to do.

So, you'll be able to refer back to that to help you.

So, I've started off, I've got, define my subroutine, called welcome, and now I'm going to put the code that I want to happen, when this subroutine is called.

And the code that I want to happen is print.

And I'm going to put hello world.

It is traditional, for every new programmer, to display hello world on the screen, as their first bit of code, so that's what I want you to do this lesson too.

So, I've done there, print hello world, and hopefully you noticed again, let me just do it again so that it wasn't too quick.

So, I open bracket, and then he put that second bracket there for me, to remind me that it needs to be there.

I also put one speech mark, and it put another speech mark in next to it, because it's helping me out.

My Integrated Development Environment is helping me out by putting little tips there.

You'll also notice that as I write, it gives me little clues about what kind of things that I can write in there.

Now, you don't need to pay much attention to those right now, but the more and more you get into programming, the more those tips are going to be helpful for you.

So, now I'm going to type in hello world, and there is my bit of code.

Now, this is a subroutine.

So, I've got there, define a subroutine called welcome.

And this subroutine is going to run the instruction, print hello world.

Now, at the moment I haven't called my subroutine.

So, if I run my programme, and I'll do that now, nothing's going to happen.

And that's because all I've done is I've said, here's a subroutine, here's what I want to happen in that subroutine.

But I haven't called that subroutine.

So, I need to put a subroutine call in, in order to make that programme run, that subroutine.

So, I'm going to call it by just typing, welcome, open bracket, close bracket.

And did you see how my Integrated Development Environment started to help me out there? So, I put welcome, so W.

I literally just put W and it gave me a clue there, it found the subroutine, and it started to give me a clue about what I needed to type.

So, I could actually just click there, without having to write it.

I do need to put the little brackets there.

And then it does it for me.

So, it is quite helpful there.

So, now I've called that subroutine.

What it will do, is it'll go through each line of code in turn.

So, it'll create this subroutine, and then it'll get to line four, and it'll call the subroutine and go to these instructions.

So, let's make a little prediction now.

What do you think's going to happen, when this programme is executed? Pause the video while you have a little think about that.

let's run the programme then and see what happens.

Were you right? Did anything surprise you about that? Did you expect to see speech marks maybe? So, what is done is it's printed the string, hello world.

So, anything that's inside those speech marks there, in that print function, has been displayed as output, on my screen.

Now, before I let you have a go yourselves, what I want you to do, is just have a look at some common syntax errors.

Now, I showed you a logic error, which was this one, first of all.

So, that was a logic error.

It's not running as it's expected.

There has been no syntax errors come up, on this right-hand side, and you'll see a syntax error very shortly.

But, it's run, but no errors have happened, and it's not working as I'd expected.

And that's called a logic error.

Now, logic errors happen, because I haven't called the subroutine.

So, I'm going to just put that subroutine call back in.

And now, when I run it, I don't get any errors.

Now, if I was to miss out a speech mark here, it's giving me a clue already, because the syntax colouring has changed.

But, if I hadn't noticed, and then I run, this is what might happen.

So, now I've got a syntax error, and you can see it's a syntax error, because here it says, syntax error, invalid syntax.

And it actually says to me, that it doesn't like something that's happened on line two.

And it's pointing towards this hello world thing.

So, if I go over to line two, I can see that this is where my syntax error is.

And if I have my checklist here, then I'd know that print statements, if I'm going to print some string, I need to have speech marks either side.

So, I would know that my speech mark is missing.

And then when I run the code again, I don't get that error message.

Another common error that people make, is they put a capital P, for print.

So, I'm just going to run and I'll just show you what happens there.

So, now we've got a slightly longer syntax error, but if you look at that bottom line, it says name error, name print is not defined.

So, it doesn't know what it wants you to do with this print, because it doesn't exist.

Now, it doesn't exist because print with a capital P, doesn't exist.

So, we need to know that we've got to change it to a lower case P.

Now, when I've fixed it, I don't get a syntax error anymore.

Other things that you might do, like missing colons, for example.

So, I'm just going to run it again.

So, this time we just get syntax error, invalid syntax, and it's pointing, you can see a little arrow, pointing towards where it might be, and then I could go, oh yeah, I need a colon.

So, all sorts of syntax errors are going to happen to you when you start typing this in, it's totally normal, and it's just about learning how to spot them, and how to fix them.

And that's why those syntax checklists are really important.

You're going to have a go at doing that now.

What I'd like you to do then is use the worksheet, to help you write your first Python code.

Pause the video while you have a go at that.

Fantastic.

So, we're going to be starting to look at sequencing and thinking about how we can start building our own programmes.

So, precise instructions are very important in programming.

You also need to make sure that your code is written in the correct sequence.

A sequence of instructions, will be read from top to bottom, performing each instruction in turn.

A karaoke programme has been created to help a class of nursery children, remember the words to twinkle twinkle little star.

You will need to investigate the code, to see how it works, and then modify it, so that it is finished.

So, you're going to be using a worksheet now.

And what I want you to do, is to follow the instructions on that worksheet really, really carefully.

And have a good go.

And then I'll be here afterwards, to take you through the solutions.

So pause the video, while you have a go.

let's take a look then, at how you could have solved the twinkle twinkle little sequence problem.

Hopefully you were fine with making your prediction, and then running the programme, to see if your prediction was correct or not.

So, I'm going to take you through, what you should have put for the answers, for the investigate section.

So, I'm going to look at step one first of all.

Now, step one said to execute the programme, and what was displayed when you executed? So, that much just means, click run.

And what happens is, it goes twinkle, twinkle, little star, how I wonder what you are, and then it stops.

So, it doesn't do anything else.

So, hopefully you had for step one, something a little bit like that.

Now, step two says, which line contains the subroutine called, twinkle? So, you had to look down there, and see if you could find the line of code, that has got the subroutine called.

and there we go, it's line 13.

For step three, it said, why does the programme not display the rest of the nursery rhyme? So, if you take a look, you've got here, one subroutine called, twinkle, and then you've got another subroutine called, up above.

But the only subroutine that has actually been called is twinkle.

The up above subroutine, has not been called.

So, that's why that part of the programme has not happened.

The next part of it hasn't come.

So, step four, it says, on line five change sleep to sleep.

So, I need to find line five, and I need to change it to seven.

What happens when you run the code? So lets have a look.

Twinkle, twinkle little star, It's taking some time.

So, it takes a lot longer, this time, to get to, how I wonder what you are.

So, it gives you a little bit clue, what about, what it might actually be doing there.

It says, make sure you change it back to three, oops.

Which I have done there.

What do you think the sleep subroutine is doing? Now, what the sleep subroutine is doing, is it's pausing the programme, for the amount of time that we have there.

So, when I had seven, it was pausing it for seven seconds, and when I've got three in there, it's going to pause it for three seconds.

So, that's what it's doing.

And then finally for step six, it says, remove the code from line one and run the code.

What happens? So, I'm going to get rid of that.

I'm going to run the code, and we've got an error, and it's coming up a name error, sleep is not defined.

It says, make sure that you put the line of code back in, before moving on.

So, from time import sleep.

Okay, so, that line of code there is really, really important, because what it's doing, is it's actually importing a module, and is importing a function from that module, or a subroutine, that I can use here, in my programme.

So, it's vital that that is there.

If I want to use sleep anywhere in my programme, I've got to first of all, important at the top.

And this is just another subroutine, that somebody else has written, it's built into Python, and I can access it whenever I like, by just using that line of code at the top, and then that other line of code in there.

And we'll learn more about things like that, as we go through this programme.

Let's take a look then at the next part.

So, the next part was to modify the programme, and you were given some steps to do.

So, it says, add a line of code, that will call the subroutine, up above.

So, I'm going to take a good guess, that up above is going to be after, twinkle twinkle.

So, I've done that there, and I'm going to run my programme.

♪ Twinkle, twinkle little star ♪ ♪ How I wonder what you are ♪ ♪ Up above the world so high ♪ ♪ Like a diamond in the sky ♪ So, it happened super, super quickly there, didn't it? It put with two lines of code at the same time.

So, it's not quite a karaoke programme at the moment.

So, then it says, add two de-sleep function calls, that will pause the programme for the correct amount of time.

So, I'm going to guess that it's three.

So, it's sleep, three, and then the same for there, sleep, three.

And then I can run it again.

It says, your code is still not complete, add one more line of code, to make the entire nursery rhyme appear, when the programme is executed.

So, let me just think, so, you've got, ♪ Twinkle, twinkle little star ♪ ♪ How I wonder what you are ♪ ♪ Up above the world so high ♪ ♪ Like a diamond in the sky ♪ ♪ Twinkle, twinkle little star ♪ ♪ How I wonder what you are ♪ So, I actually need another subroutine call underneath, that does those lyrics again.

So, now I'm going to run the programme and see if it works.

Here we go, ♪ Twinkle, twinkle little star ♪ ♪ How I wonder what you are ♪ ♪ Up above the world so high ♪ ♪ Like a diamond in the sky ♪ ♪ Twinkle, twinkle little star ♪ ♪ How I wonder what you are ♪ Awesome! So, now I've got a working twinkle, twinkle little star programme.

And your make task, was to make a programme using your own lyrics.

So, thinking about other songs, that you might want to use, and using your own lyrics.

So, that's a good main challenge for you to have a go at too.

Now, I haven't done one of those, but hopefully you'll be able to use the code that's there, on the screen, to help you do that.

Let's have a little practise then, at looking at some code and see if you can figure out, what might happen when it's executed.

So, here's your first one.

You have made a welcome screen for a game.

What will appear on the screen when this code executes? So, you've got four options there.

Pause the video, while you think about what you might put.

So, first of all you said, hello world, will appear.

And then secondly, you've got hello world in speech marks, will appear.

You've also got nothing, and then you've got welcome, will appear.

So, which one did you pick? Let's see what the correct answer is.

So, it would actually be nothing.

If you don't have a subroutine call there, then all it will do is, it'll tell the programme, that it wants to create a subroutine and perform these instructions when it's called.

But if you don't have that call there, then it won't actually call those instructions.

So, it's really important to remember that call.

What about this one then? What will appear on the screen, when this code executes? Take a good look, pause the video.

Right, so you've got b followed by a, a followed by b, nothing, or, letter a, letter b.

let's take a look.

So, the answer was a followed by b.

Now, if you'd look, the subroutines were created in a different order.

So, the first subroutine was letter b, the second subroutine was letter a.

Now, it doesn't matter what order we create those subroutines in, as long as we call them in the correct order.

So, if you look there, on line six, letter a has called the function, or the subroutine, letter a.

So, it's going to print, a.

You then have got line seven, where it's called the letter b subroutine, and that's going to print the letter b.

So, then you're going to see a b.

Let's look at the next one then.

So, what will happen when this code is executed? Have a good look, and see if you can figure out which one it is.

Pause the video.

So, your options were syntax error on line two, syntax error on line three, nothing, or hello world, will appear? Now, I'll give you a clue, it's definitely going to be a syntax error, but did you spot what that syntax error was? The syntax error, is going to be on line two.

So, if you take a look there, print has got a capital P, and you'll get that print not defined, error message, because print hasn't been defined, with a capital P, but it has been defined the lower case P.

So, whenever you use print, make sure you use a lower case P.

Fantastic! So, we've got through writing our first Python programmes, using the Repl.

it accounts, and you've also, played around with a programme that's already been created.

You've modified it, and you've made your own version of that.

That's quite a lot to achieve in one lesson.

So, well done, give yourself a pat on the back.

Now, I'd really love to see what you've been getting up to this lesson, and if you'd like to, please ask your parent or carer to share your work, on Instagram, Facebook, or Twitter, tagging @OakNational and #LearnwithOak, cause I'd love to see what you've done in this lesson.

And I'll see you again soon, for lesson three.