2 hours 30 minutes
And to do that, we could make use of yet another very handy python helper function called is Numeric.
And to show you what that is, we're actually gonna real quick open our pipe on interpreter.
And we're gonna say that
s one equals the string. 1234
And then we're going to use as one that is America.
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
us to dot is in America,
Anything's gonna happen there.
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,
but for what we're doing right now, for what we're working on for this program
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.
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.
If it's a string, it's not a number rather will record. It is a strength.
So here we're going to do list called numb tokens,
and we'll just define that as an empty list. And then we're going to do stir tokens.
I will find that as an empty list,
and then, instead of down here instead of printing are split data.
Get rid of that line.
We're going to say
four eye in split
Numb tokens. Got a pen
Slightly misspoke. There sorry. If
I dot is America,
then we're going to do nothing. Cocaine's
Stir tokens dot depend I.
And then once that Luke has finished its execution,
we can say
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
in nomine tokens,
and that should do it for us. Now, let's have a look at this.
drunk there. And 5432
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.