2.2 Using Inputs Effectively Part 2
Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or
Already have an account? Sign In »

Video Transcription
00:00
And to do that, we could make use of yet another very handy python helper function called is Numeric.
00:06
And to show you what that is, we're actually gonna real quick open our pipe on interpreter.
00:11
And we're gonna say that
00:13
s one equals the string. 1234
00:19
And then we're going to use as one that is America.
00:23
So this is a method of strings, and when we run it, we can see that it's going to return. True in the case that all of these are numbers. If, however, we were to do as to
00:34
equals one,
00:36
two
00:37
that four
00:40
us to dot is in America,
00:42
Anything's gonna happen there.
00:44
We're going to get false because the letter F is not considered numeric Now, this is not an extremely smart function. It's generally going toe, assume based 10 and perform some some basic assumptions like that. That will mean that a lot of numbers aren't going to quite work correctly in it. On did some of the behaviour might be a little bit tricky to work with,
01:02
but for what we're doing right now, for what we're working on for this program
01:06
is America is going to be just fine as our we're gonna quit this interpreter. I'm going to go back to our actual interpreter program, which is now I'm just realizing a terrible name that I should not have used, but that's okay.
01:18
So we said that our two objectives here are to identify the number and type of the tokens. So we figured out we can identify which tokens are numbers. And the easy thing here is that with our basic logic, it since we say that we're only accepting numbers and strings as our types, we don't really have to do any other check. If it's a number than fantastic will record, it is the number.
01:38
If it's a string, it's not a number rather will record. It is a strength.
01:42
So here we're going to do list called numb tokens,
01:47
and we'll just define that as an empty list. And then we're going to do stir tokens.
01:53
I will find that as an empty list,
01:56
and then, instead of down here instead of printing are split data.
02:00
Get rid of that line.
02:02
We're going to say
02:04
four eye in split
02:07
data.
02:10
Numb tokens. Got a pen
02:14
all right.
02:16
Slightly misspoke. There sorry. If
02:23
I dot is America,
02:27
then we're going to do nothing. Cocaine's
02:31
got upend.
02:32
Bye.
02:35
What else?
02:38
Stir tokens dot depend I.
02:42
And then once that Luke has finished its execution,
02:45
we can say
02:51
stream tokens,
02:59
new line
03:01
Merrick tokens,
03:08
and then that'll be dot format. And this is gonna get a little wonky because of the size of the fun that I'm using on. We'll do format with Len
03:17
stir tokens,
03:21
lend
03:23
in nomine tokens,
03:29
and that should do it for us. Now, let's have a look at this.
03:36
Just one
03:38
drunk there. And 5432
03:44
And you can see here that it gave us back for string tokens and zero in America tokens. Now, the reason for that is because of the fact that we still have all of this junk white space. So we have to get rid of that before this interpreter is going to work correctly.
Up Next
Similar Content