Motive There are different types of modules in python which not everyone knows so we thought of introducing them to you guys. Let's start! Note: This is not a tutorial of how to use these but is to show that these modules also exist and if you want to know more you can visit there own page and if you want us to explain leave a comment below. Links to there page are also given below. Hope you found something useful. 1.Wikipedia Yes, there is a module called Wikipedia in python, you can easily install Wikipedia by pip install wikipedia . We cannot rely on this module for advanced use. It was designed for ease of use and simplicity. Learn More Here . Here is a simple example: import wikipedia wikiPython = wikipedia.summary("Python", sentences=2) print(wikiPython) One big disadvantage is that it works only if the internet is connected to your device. You can even control the number of sentences that you
Motive
If you have read my other blogs you might have understood that I watch a lot of YouTube videos, Today I came across a video the made a Password generator. But that doesn't work as expected to work.
All it does it shuffles all letters and number and the pick some out according to the length we gave at the beginning of the program. But here comes the problem it does not always have all numbers and special characters and some times it's just even though we have given all the necessary characters. So I taught about an alternative.
The Project
All we need is to import is a module called string and random. Which are pre-installed in python so no pip install needed:
String is a module which gives access to all alphabets, uppercase and lowercase. Numbers and Special Characters. Even though we could write all those, it is a bit easier to do it this way. Check out their article to learn more, String, I suggest you check that out.
Random is a simple module that allows us to get random numbers or Shuffle a list and so on.
check their article for more information, Random.
First, let's get all the alphabets, numbers and special characters into a list and then shuffle them with the help of the module we imported:
In the first line, we take all the lowercase alphabets and convert it into a list and then shuffle the list. We do the same for uppercase, numbers and special characters.
Now let's move to the next step:
Here, we have made a variable called length which asks us for the length of the password and convert it into an integer. Then we create an empty list called passwordList.
Now we add different characters to our passwordList:
But now we get an error:
This error is because the index becomes 10, and but we have only till index 9 for numbers so we need to change some:
Here, I have created some new variables which are set to zero and checked the length of these lists and if the index is less than then length f the ist we add one and if the index reaches the length of the list we make the index to zero. If the length of the passwordList we break out of the loop.
Here, we convert the list into a string and store it in a variable which is form index 0 to the length of the password. But after we print the password always the first character will be an uppercase second case will be lowercase and third will be a number and forth will be a special character and so on. So we shuffle the list before converting it into a string.
Now we get a totally unique password with all characters in it. But it's hard to remember these passwords so we save it into a file:
After printing the password the program asks us whether we need to save the file if so it creates a file named Password.txt if it's not created and stores the password there.
If you have any doubts or errors in the program feel free to comment down below and I will respond as early as possible. And if I have made any mistake please correct me in the comment box below. Don't forget to follow us for such python related content.
Awesome!!!!
ReplyDeleteThank you!
Delete