filmov
tv
#100DaysOfCoding - Random Password Generator - Python Code - Day 5 Challenge #5 (Final Challenge)

Показать описание
#100DaysOfCoding - Random Password Generator - Python Code - Day 5 Challenge #5 (Final Challenge)
What’s up? I trust you are well.
In this video, we gonna build a Python Random Password Generator. This is the last exercise challenge for day 05 of my #100DasyOfCode course.
If you are interested in learning Python, I’ll put the link to the course in the description.
The code begins by specifying the letters of the alphabet in lowercase and in uppercase that are in a list. Then, followed by numbers (also in the list), and finally, symbols. These are the most commonly accepted characters you can use when creating passwords to any websites you signed up to.
Then we have a print statement welcoming the user to the Python Password Generator.
Then some user input statements in terms of how many letters, symbols and numbers do you want in your password.
We will be needing the random module function here to generate for us the random letters, symbols and numbers.
The first part of the exercise is to generate a password with, for instance, 4 letters, 2 symbols and 2 numbers where the order is not randomised, meaning, the output should be arranged as 4 letters, 2 symbols and 2 numbers.
The second part of the exercise is the upgrade version of the first part where after specifying the user input, you need to combine them all and randomise them.
So, let’s get started.
The process is to use the for loop function to get the random letters, symbols and numbers according to the user input.
So, we can say:
For letter in range(0, nr_letter): #if the user wants 4 letters for the password, the range will be from 0 to 3 which gives us 4 characters. You may write it range(1, nr_letter + 1).
Next line will be password_letters = password_letters + random_letters
Pay attention to the warning next to the line number which tells us that we need to specify the initial value of the password_letters. So let’s add it before the for loop begins by saying password_letter = open and close double quote which means a blank string.
Then finally, let’s print the output using the print statement which is print(password_letters). Take note of the indentation. If you put it inside the for loop, it will continue to print until the loop stops and it’s ok if you want to see what’s going to happen but I only want to see the final output, so I’ll remove the indentation.
By the way, line 24 code can be written as password_letters += random_letters.
And we are done with the letters.
Do the same code arrangement for symbols and numbers. You may copy and paste the code if you think it will be quicker for you than typing again those lines of code. Then don’t forget to replace all letters wording with symbols/numbers.
Alright, it’s time now to combine all these characters to form a random password by assigning it to a variable called random_password (you may give it a different name) which is equal to the new value of our password_letters + password_symbols + password_numbers.
Finally, to complete the first part of this challenge, let’s create a print statement
So, print(random_password)
Cool. Let’s move now to the hard level where instead of having the generated password in letters, symbols, numbers sequence, we will randomise it at this level.
The first thing we need to do is to convert the random_password from line 44 to a list. Let’s do that by saying: new_list = list(random_password)
Then let’s view the result using the print statement by saying print(new_list).
Then let’s view the result using the print statement by saying print(new_list).
Finally, time to join back those characters in a list using the join() function
Then let’s view the final result using the print statement by saying print(final_password).
There you have it. It’s time now to compare my solution to my instructor’s solution.
Thank you for watching this far and if you are interested to know what I’m learning in this 100 days of code online course, why don’t you subscribe to my channel and hit that notification bell so you’ll be notified of my future video uploads.
Have a great day and thank you once again for watching.
Cheers.
Join this channel to get access to perks:
What’s up? I trust you are well.
In this video, we gonna build a Python Random Password Generator. This is the last exercise challenge for day 05 of my #100DasyOfCode course.
If you are interested in learning Python, I’ll put the link to the course in the description.
The code begins by specifying the letters of the alphabet in lowercase and in uppercase that are in a list. Then, followed by numbers (also in the list), and finally, symbols. These are the most commonly accepted characters you can use when creating passwords to any websites you signed up to.
Then we have a print statement welcoming the user to the Python Password Generator.
Then some user input statements in terms of how many letters, symbols and numbers do you want in your password.
We will be needing the random module function here to generate for us the random letters, symbols and numbers.
The first part of the exercise is to generate a password with, for instance, 4 letters, 2 symbols and 2 numbers where the order is not randomised, meaning, the output should be arranged as 4 letters, 2 symbols and 2 numbers.
The second part of the exercise is the upgrade version of the first part where after specifying the user input, you need to combine them all and randomise them.
So, let’s get started.
The process is to use the for loop function to get the random letters, symbols and numbers according to the user input.
So, we can say:
For letter in range(0, nr_letter): #if the user wants 4 letters for the password, the range will be from 0 to 3 which gives us 4 characters. You may write it range(1, nr_letter + 1).
Next line will be password_letters = password_letters + random_letters
Pay attention to the warning next to the line number which tells us that we need to specify the initial value of the password_letters. So let’s add it before the for loop begins by saying password_letter = open and close double quote which means a blank string.
Then finally, let’s print the output using the print statement which is print(password_letters). Take note of the indentation. If you put it inside the for loop, it will continue to print until the loop stops and it’s ok if you want to see what’s going to happen but I only want to see the final output, so I’ll remove the indentation.
By the way, line 24 code can be written as password_letters += random_letters.
And we are done with the letters.
Do the same code arrangement for symbols and numbers. You may copy and paste the code if you think it will be quicker for you than typing again those lines of code. Then don’t forget to replace all letters wording with symbols/numbers.
Alright, it’s time now to combine all these characters to form a random password by assigning it to a variable called random_password (you may give it a different name) which is equal to the new value of our password_letters + password_symbols + password_numbers.
Finally, to complete the first part of this challenge, let’s create a print statement
So, print(random_password)
Cool. Let’s move now to the hard level where instead of having the generated password in letters, symbols, numbers sequence, we will randomise it at this level.
The first thing we need to do is to convert the random_password from line 44 to a list. Let’s do that by saying: new_list = list(random_password)
Then let’s view the result using the print statement by saying print(new_list).
Then let’s view the result using the print statement by saying print(new_list).
Finally, time to join back those characters in a list using the join() function
Then let’s view the final result using the print statement by saying print(final_password).
There you have it. It’s time now to compare my solution to my instructor’s solution.
Thank you for watching this far and if you are interested to know what I’m learning in this 100 days of code online course, why don’t you subscribe to my channel and hit that notification bell so you’ll be notified of my future video uploads.
Have a great day and thank you once again for watching.
Cheers.
Join this channel to get access to perks:
Комментарии