00:03
So in this problem we have been asked to get an input from the user for up to a letter with word with 10 letters and we must write a program that will reverse the order of these letters and type it back as an output and we are told that we don't need to make a function out of it so we'll just make a very simple program and we are also told that we should take the period or the full stop as the end of the input.
00:40
So with this, let's start.
00:44
So first we will use the input command in python.
00:50
So just to clarify i'm using python here because it's much simpler and easy to understand here.
00:56
So in python input command takes input from the user.
01:04
I'll show you how it happens.
01:08
So once you execute this command command, it will take an input and it will assign.
01:12
It to a variable.
01:19
You can use it for that.
01:21
That's the first thing we'll do to take the input.
01:24
And the next thing we'll do is we'll find the length of the input and we'll find out where is the period located.
01:52
Because that's where we are only supposed to consider the input only up to that point.
01:57
So for example we have an input which is some letters here and then we have a period and then we have a few more letters right.
02:08
So what we are trying to do is that we want an output which is this goes here, this goes here, this goes here, this goes here, this goes here, this goes here.
02:23
We want to reverse the order but we don't want to consider anything that is anything including and after the period.
02:32
So we want to flip this portion only, right? so that's what we'll be using in this case.
02:42
So with that we then use this method that i just explained that we will basically take the first element or maybe let's say the last element and then put it in the first portion.
02:57
Then we take the second last element and put it in the second one.
03:00
Third last we put in third.
03:01
Fourth last we put in fourth and fifth last we put in the fifth last we put in the fifth.
03:05
Position or whatever the end's position is and we just type it out and while we do this we are basically going to concatenate these characters one one single characters into a string and that in python is very simple i'll show you so with this let's look at the program that have built here on the side so the first thing we do is we use the input command in this line and we assign as we have been told the input into an array called letterbox and this will be an array of characters which is a string so we tell the input or the user that the type of word which is up to 10 letters only so this is asked in the question so i've taken an example where i have actually gone and put some a space and a h character after the period and this is actually one two three four five six seven eight nine ten eleven okay i'm sorry it's eleven letters but we are not enforcing it in this program if you want to enforce in this program it becomes a bit long but i think this not a critical requirement of this program so you can for your example you can use a shorter one or two characters shorter thing but i just want to show you the working of this program what happens when you have characters beyond this and how does this program deal with that so just to confirm we type in the array into the into the python terminal and we see that this is the input which includes the part that is after the period so then as we explain first find the length because we want to know over what length should we iterate this procedure where we are going to swap the order of the letters we need the length of that because if you're going to iterate from the first letter of the string to the last letter we should know how long will that procedure be.
05:10
So for that the l variable is storing the length of the array.
05:15
And then we use a method called find for strings where we can find the location or the index number of the character in the string where it matches the input of the find operation.
05:33
And in this case we have told this function to find out where this function to find out where it matches the input of the find operation.
05:39
Where is the period located and store that value of location into s.
05:44
Now the good thing about python is that in case, in case period is not found, right? it could be.
06:03
So if in case your input does not have the period, so period will not be found.
06:08
And in this case, s will be equal to minus one.
06:11
That's the default.
06:14
So in our case it will be one, two, three, four, five, six, seven.
06:19
8, 9.
06:21
So the value of this s will be 8 because it's on the 9th position and the index starts from 0 in python.
06:30
So this value value of s will be 8 in this case.
06:33
But if it's not found it will be minus 1.
06:34
And when it's minus 1, we don't know what to do with this...