Welcome back. So now let's move on to the first main function for the program
that would allow the user to register.
All right. So
let's go all the way to the top in here and let's push
the user interface function all the way down. And let's come up here.
Actually, I'm just going to add a note and say regis registration
uh function.
OK.
OK. So what do we call the function? Let's say register
underscore user.
All right,
we're just a user brackets. Let's add a colon.
OK.
So we want to accept the user username and a password. So let's prompt them to do that.
All right. So I'm gonna say username
equals and now inputs
in brackets, let's say enter a username
colon.
Ok.
And then let us prompt them for the password as well. So password
equals
input and then in brackets
enter a password
colon and there you go.
All right. So right now, once the user has provided the username and the password,
we would like to store them in a file, we can call the file users dot TXT as an example.
Ok. So
what we're gonna do is
we are going to say with
and now open, remember we need this function to create our file.
So now let us add the name of the file. I'm going to call it users
dot txt.
And now let us enable the append mode.
So I'm gonna say a
OK. And then as well as file
colon.
All right. And now
we can use the right function. So I'll say file dot right.
And now in brackets,
we can use our F string.
And then let us add a codes,
color braces, user
name.
Let's close that.
And then we can also add a column to separate the password from the username.
So col braces again
and then we can add a password.
And then for good measure,
we can do the
uh backward slash and then n
so that each user
information will be stored on a separate line.
Each user credential will be stored on a separate line
and it is OK.
All we gotta do right now is we can print out
a simple message
that would say something like print. And then we can say
uh user registration
was successful.
OK.
And there it is. OK.
So how do we now integrate our registration function with the main function itself?
What we're gonna do right now is we're going to come
all the way right here and say if choice equals one,
then we can remove this.
We no longer need this print statement
and we will just call the function and the
function that we created here was what register on
user. So right here,
I'll just say register
underscore user
and then brackets
and then there it is. So hopefully,
uh this should work. Let's go ahead right now and test it.
So I'm gonna run the program.
Ok?
Number one, we want to register press enter, enter, username.
I'm going, I'm gonna go with Alex password. I'll just go with Alex again. Ok.
Just for a test
enter and ok,
user registration was successful
and we have our users dot TXT file in here
and if I open it up, awesome. You can see it says Alex. Alex. So fantastic.
We can see right now that it's actually working so far. So good.
Join me in the next lesson where we will now create
the function that will allow our users to log in.