# Lesson video

In progress...

Hello and welcome back to programming part 5.

Strings and Lists.

I'm Ben, your Computing teacher for this lesson.

And this is lesson 4, string cuddling part three.

What we're going to do is we're going to put into practise those string operations that you learned about in lessons two and three and put them together in one bigger project.

Okay.

Now all you'll need for this lesson is your computer and a web browser.

Do ask your parents or carers for permission before accessing that account.

Okay.

If you can clear away any distractions that you might have if you've got a nice quiet place to work that'd be great too.

Okay.

When you're ready, let's get started.

Okay.

In this lesson you will create a programme that uses string handling techniques.

Okay.

First of all as ever I'm going to ask you to make a prediction.

Now, if you do have your ASCII chart to hunt then that would also be helpful in helping you answer this one.

Okay.

I would like you to read that code.

Okay.

And then I would like to tell me what do you think the outputs of print will be when this programme is executed? Do you think it'll be a single random capital letter? Do you think it would be a single random lowercase letter? Do you think it would be a random on score character? Or do you think it would be a single number? Okay.

What do you think? Now if you've not yet got your ASCHII chart don't worry about it just make an educated guess.

Okay? What do you think? Is it one, two, three or four? Let's go through the answer.

You shout it.

Shout out for me.

Three, two, one.

It is one.

It was actually one.

It was a single random capital letter.

Okay.

Then the reason for that is because anywhere on the ASCII table between 65 to 90 are all capital letters of the alphabet.

The programme generates a random capital letter.

Okay.

Cause we're importing random.

We got random number being a variable there and using that randant between 65 and 90.

That's going to generate a random and it's just somewhere between 65 and 90.

Then what we do is we pass that into the child function we learnt about in lesson 3.

Okay.

We put in that random number in the chart store then into the variable random character.

That's going to print one of those random characters between 65 and 90.

Cause the chart function number returns the character back from the ASCHII table.

Okay.

What I'd like to do now is I'd like to pause the video and the main bulk of this lesson is to go over to task one on your worksheet and have a look at the activities on there.

Okay.

And the attempt here is to build a programme using those skills that we've learned about in the previous two lessons.

Okay.

It's really important that you look at the code snippets because there are some code snippets there that'll help you.

But also don't be afraid to look over the code that you've built and you've made over the past two lessons as well cause that will definitely really help as well.

Okay.

I'd like to give OCO go.

And what we're going to do is when you input the deal I'm going to go through the solution.

Now I don't want you go ahead and look at the solution until you're ready.

Either that means until you finished it or until you got to a part where you can't continue.

Okay.

Now if you've got to that part that you feel you can't continue, try and help yourself first.

Okay.

And that is looking back over your previous work from the previous lessons.

Okay.

And if that still doesn't help then watch a video and then that hopefully will help you become unstuck.

Okay.

Good luck.

Have fun with it.

And then unpause the video when you're ready.

Okay.

As promised, I'm going to go through the solution but as I also mentioned before then if you're a little bit stuck on certain part, wait till I've described that part then pause.

Okay.

And then go back to your own code and see if you can work it out and complete it based on what I've shown you on set.

Okay.

Please don't just copy and paste the solution.

First of we needed to import random because we'll use that later on.

Okay.

Now that might not have been the first thing that you did but that's okay.

You can just add it in when you get to the part where you actually need that.

But what's always helpful if you put that line at the top of the programme.

Okay.

Right.

The first task was to ask for three words to be inputted.

Okay.

And they also should have been converted to lowercase.

You can see here my first chunk of code I've got print enter word one and then I've got a variable here word one equals inputs.

It's asking for the input but I'm also therefore straight away converting the answer to lowercase.

Okay.

You can do it that way.

You could also have done it over written word one by putting word one equals word one dot lower.

That would be fine too.

Become just do it in a single line.

If I repeated that process for the first three words needs to be input and that takes me to line eight.

Okay.

Then the next task was to concatenate those words.

Okay.

Make the three words into one single string with no spaces.

The way we did that is we use that plus operator.

Okay.

I created a variable here called three words equals word one plus word two plus word three.

Okay.

I was not going to put any spaces in between them.

It's going to use the exact characters that the user inputted and join them together.

Okay.

Then what I've done is I've created an empty string for password.

Okay.

The next task was to go through.

Was to iterate through that string.

This what I've called three words that can cut Nate in three words They're all lower case.

And every time we got to want them vowels change it to a certain character.

Now we said, if the letter was.

And you saw on the table on your worksheet.

If the letter was an A, one of the vowels, then it needs to be a random number between 33 and 37.

E was 38 to 42.

I 43 to 47.

O 58 to 61.

And U 91 to 94.

These blocks are really similar to each other.

Okay.

But let me just explain one of them.

For each letter in three words we're using our four loop there for each.

It's going to iterate through the three words there.

Each letter it comes across, If the letter is an A for example what we'll do here is generate that random number.

Okay.

Between 33 and 37 sorry.

Then what we do is we create a new variable here.

Random character equals I'm using that CHF function there and passing into it that random number that's just been generated.

A number between 33 and 37.

Okay.

That will what.

If you remember what CHR does the child does.

It returns back the character.

Okay.

It's going to do random characters and masky table between 33 and 37.

Okay.

While it's a it then upset on to the password.

The password starts off as a blank string.

What we're doing is we're adding to the string by going password equals password plus the new random character.

We're taking our password string and adding onto it that random character.

It was A is the same for I only different random numbers.

Same for E.

Sorry.

Same for I same for O same for U.

And if it's none of those all we're doing is we're taking the Pasco string and adding to it the normal letter.

The letter that was already there in the first place.

Okay.

By the time we iterated through it was either added the normal letter or added that new random character.

Okay.

We go.

I'm going to print password at the end.

When it's finished it's just going to print the result of the password.

Let's test that out.

Shall we? I'll run this.

Okay.

My password possibly predictably, I'm going to put computing is great.

And finally said one sorry.

Computing is great.

Okay.

There we go.

And look.

Can you see the way it's converted? Could see it's not an A, E, I, O or U.

It's moved it to lowercase and then should place the vowels.

There we go, these random strings.

And I bet you if I plot.

In fact, let me run this again.

I don't know if it keeps up but let me just copy that for a second.

Okay.

Let's run that again.

I'll catch wind of it.

I'm going to put it again.

Computing is great.

I should in theory use a different password.

You can easily see is slightly different there.

Okay.

Definitely is long cause I remember had a.

I think there's a left thumb symbol there as well.

Every time it's producing something with a random character freed from the vowels.

Okay.

That's the solution so let's head back over to the slides.

Okay.

If you manage to do that a big well done.

You should give yourself a big pat on the back.

Because what you've done is you've not only taken the new programme and skills you got to deal with in the past two lessons.

But actually also you've combined that with all that programming knowledge that you gained over the past three units as well.

Okay.

You might have noticed that each one of these programming challenges were giving you.

Just increase in complexity every time.

If you've managed it really well done from me.

Okay.

Now to finish off this lesson what I'd like to do is I'd like to solve the string handling anagrams. Okay.

These are all words that might be familiar to you after the work that we've been doing over the last few lessons.

But of course because of anagrams, all the lessons are being jumbled up.

There's no computer programme here.

I would just like you to use your brain power to see if you can mix up the letters but to follow an actual word that we know.

Okay.

If you finish up really, really quickly you're really good at solving anagrams then you can.

What I'd like to do is maybe two of you can find out what the actual definitions are for these anagrams. Okay.

Pause the video now and then once you got the answers then you can unpause.

Okay.

So take it you unpausing cause you've got the answers.

Let's have a looks see if you were right.

They were substring, concatenate, element and index.

Okay.

That's all for this lesson.

And that's all for this section of lessons about strings.

It's not the end of the unit yet but is certainly is under the section about strings.

The next lesson we're going to look at a raising list.

But like I said, if you've managed to do everything today big well done from me and I would really love to see your work.

I'd love to see your solutions to the problems. Okay.

If you'd like to share those with me please do so.