Skip to main content

5 Unique and Useful Python modules.

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

Python Password Generator

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.


Comments

Post a Comment

Popular posts from this blog

Digital Clock | Python | Pygame

  Motive            Just to keep this the way I make other projects on my website. Just ignore this and jump right into the project. Oh and here's a preview of what we are going to make. The Project          We will be using pygame to create our Digital Clock, I believe all of you have installed pygame, if not just open the command prompt and type pip install pygame and hit enter. Learn more about pygame here  https://www.pygame.org/docs/ . Feel free to skip to the end to get the full code.           Okay back to the project, first, let's make a basic pygame window. So import pygame, initialize pygame, set an icon, make a screen like a rectangle then set its caption or whatever you call it, make a while loop to make it run till the exit button is pressed, and update the pygame display. Looks like a lot but these are necessary to even make a basic pygame project. Everyone who has at least worked with pyga

Chrome Dino Game Automation with Python.

Motive           I saw a video on YouTube that made a python program to automate the chrome dino game at the end he shows a clip of the program playing the game. But there was a problem with the code I do not work when it's dark so I thought of turning the dark mode in the laptop so that it stays dark all the time but that did not work after reaching a score of 700 it becomes day again so I have to think of an alternative see how I did it. The Project  First Import the necessary modules in your IDE import pyautogui from PIL import Image, ImageGrab import time PyAutoGUI   lets Python control the mouse and keyboard, and other GUI automation tasks.                    First, open your terminal and run pip                          learn more on   Pyautogui                    

Never Lose a Game of Chess | Python Chess Hack

Motive            I lost every game that I played chess with my friends. So why not cheat, even though  it was not the best option, I had to somehow prove that I was not dumb and can even win against them. Since they play online with me, I had a better chance to cheat so I thought of creating an ai to play against them but it was not that easy so I started surfing through the internet to find a better way. Then I found stockfish it was a chess engine that generates the best move for us. So I used it as my AI. Again, luck was with me I was able to find a module called chess in python that helped me a lot and now my work was really very easy. At last, I created the program and won the games against them but they had figured out that I was cheating and my friends started mocking at me. Then I understood that I was wrong and I shouldn't have cheated and started working hard for it and now I literally can win matches with them even though I lost many of t