Hello, everyone. And welcome back to Intermediate Python here on Cyber Eri on demand if you're watching this video, hopefully that means that you went through lesson zero, which is our introduction. You saw what our objectives are. You saw what the prerequisites are and you feel comfortable saying that this is the class for you. If you haven't checked that video out,
I do highly recommend you do. It's gonna give you some core base information, understand what we're gonna be doing in this course.
Now That said, today's video is going to be lesson one user input. It's gonna be the first of two videos in this lesson we're gonna cover to specific objectives in this video. We're going to learn to use an interpreter, input from the user. And in the next video, the next part of this lesson, we're going to learn to use command line arguments so that we can actually take
information from the user when they invoke our program
and make decisions or use that in our program in some way. Now, to do that, we're gonna go ahead. We're gonna jump into a bunch of'em over here,
and we're just gonna be working out of the soup on TVM for the whole course. A CZ you can see here. I just have my Terminator shell up and I'm gonna be working out of them as our text editor. So I understand you're to show a good way of understanding user input and interpreting it. What we want to do is we want to come up with a use case and one of the most important use cases. Here
is something that we call token ization, not organization is a fancy way of saying of describing using discrete pieces of data. So a token is really just any piece of data that would be considered atomic for your process. So any core piece of data that is, you know, the smallest thing that you referenced in your program
and a lot of cases that might be a single character and a lot of cases that might be a number. In other cases, it might be a string.
All that matters is that that is what your program uses as its atomic units, smallest unit of data.
So in this case, we're going to create a program that we're gonna called interpreter,
give our shebang line here,
and we're going to just real quick comment and say exactly what our objective is in this particular project. And in this video in general, we're gonna say we're going to create
dot Pod is a script which takes input
So that is our sort of thesis statement for this script, we're going to take an arbitrarily long input
separated by able emitter character, a sort of a special character that we're gonna use to say This is the break point between two tokens and then we're going to use that, and we're going to identify the number of tokens we got and what type they are. And for the sake of simplicity, we're only going to accept two kinds of tokens are only going to interpret do kinds of Duncan,
which is going to be strings and numbers.
And to do that, all we're gonna have to do here is we're gonna say, First of all, we're gonna say riddle, emitter
Now we're going to create our main, and the first we want to do is just make sure that we can successfully take input from the user. Now, in our last class, we did this very briefly, and it's actually not a terribly complex process. While you're going to do is create a variable which I'm going to go user data and you're going to set that equal to the results of the input function.
And the argument that you can give to input is what will be printed to the screen as a prompt.
So in our case, we're going to say
and then we're just going to print our user data as sort of sanity check
and we're gonna return.
Then we're going to go ahead and invoke me so that it will actually run.
And we're gonna go back out of here, and we're going to just make sure that we wrote our program correctly,
and you could see that it takes that input and it prints back out exactly the same way. So we're off to a good start. We're now successfully taking in storing in
Let's do something a little bit more interesting with it. Now, we talked about the fact that this pipe character is gonna be our limiter character. That's the character that tells us where to separate data. And in order to make use of that, we need to find some way to actually break the streams apart. Fortunately, Python has a really, really fantastic utility called Split
We're gonna do is we're gonna create a new variable called split data.
We're gonna sit that go to the result of user data, not split,
and it's going to take a keyword argument, which is something we'll talk about here in just a little while when we talk about taking command line or when we talk about our deep dives into modules in our later lesson. But user data not split,
we're going to say Sepp equals
and then we're going to Instead of printing user data,
we're going to print split data and see if we did this right.
And you can see now that instead of being this string with this token in it, with this organization in it, it's now been broken apart into individual characters, individual strings in this list. Now that's a good start, but we need to be able to do next. Is figure out how to break out one.
How to get rid of this nonsense whitespace year, since that's not one of our tokens or part of our tokens,
and how to interpret these numbers as numbers.