Best Simple Python Projects for Beginners | Towards Data Science

Hello readers, in this story, let’s talk about making some fun Python Projects to have a better understanding of Python and to have some fun playing with Python and its amazing libraries.
These projects are small and you can easily do these within 1–2 hours. These will help you understand Python and its various libraries in a better way. These are beginner-friendly so everyone should try his/her hands on these projects.
So, without further ado, let’s dive into the projects one by one.
This is one of the very simple python projects for you to do but is an interesting one to try. It makes use of the Google Text to Speech API of Python, so we need to import the library first using the command below:
pip install gTTS
Now, after we have installed the required libraries, we can build our python program to convert text to speech.
If we want to listen to the audio within our program, we can import the os library in the python code.
So, let’s write the code for the program. Below is the required code:
#importing the gTTS libraryfrom gtts import gTTS#Asking the user for the required textmt = input("Enter the required text:\t")#Setting the output languagelanguage = ‘en’#Converting text to speech and choosing speed as fastvoice = gTTS(text=mt, lang=language, slow=False)#Saving the speech as mp3 filevoice.save(“conv.mp3”)
So, in this way, you can very easily make a text to speech conversion using Python. The file will be saved in the same folder where you are executing this python code (the current working folder).
You can make this better in many ways like you can extract text from a pdf and then convert it to speech for reading out a pdf completely. You can also extract text from images and then do the same stuff.
So, let’s move to our second simple Python project.
You can easily extract text from images. We will be using Open CV and pytesseract library.
We need to install both openCV and pytesseract libraries first. To do so, we will use the following command to install openCV in the system.
pip install opencv-python
To install pytesseract, we need to perform more tasks. It’s the toughest part of the tutorial.
First of all, we need to use the following command:
pip install pytesseract
Then, we need to download the following file and install it in our system. Download the most suitable file for your system from here.
After doing all of this stuff, we are good to go with the final code of our program.
#Importing the librariesimport cv2import pytesseractpytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'#Opening the image with open-cvimage = cv2.imread('pic.png')#Extracting text from imagest = pytesseract.image_to_string(image)#Printing the textprint(st)
So, we have made our text from image extractor easily with the help of pytesseract library.
It has high accuracy in detecting the text from the images. So, with relatively simple code, we have made a high accuracy text from image extractor.
We can do a lot of stuff with PDFs using Python. We can convert it into text, slice the PDF, merge PDFs, add watermarks and much more. So, let’s write a simple Python Code to perform all such cool stuff on PDFs using Python.
We will be using the PyPDF2 library for performing the operations on PDFs. This library helps us to gain all those powers to do so.
So, let’s install this library by using the following command:
pip install PyPDF2
This command will install the required packages into your system. Now, we are ready to write our Python Code.
So, first, let’s import the package and load the required pdf.
#Importing the packageimport PyPDF2#Loading the PDF filepdffile = open('first.pdf', 'rb')#Reader object to read PDFsReader = PyPDF2.PdfFileReader(pdffile)
Now, let’s extract some information from the PDF.
#Display the number of pagesprint(Reader.numPages)#Getting a page by page numberpage = Reader.getPage(1)#Extracting text from the pageprint(page.extractText())
We can also merge PDF files, rotate the pages in PDF file, split PDFs into multiple parts and many more such things. But, we can not cover all of these here.
For more information on this library and its usages, visit PyPDF2 here.
There is an amazing API which will help us translate from one language to the other. This is the Google Translate API. We will need to install goslate in our system to run the Python code needed to perform the translation.
pip install goslate
Now, let’s delve into the actual Python Code. We can translate to many languages which all are supported by Google Translate API. We will be taking the input from the user as a string but we can also take input as a form of a text file, convert into a string and perform the operation on it.
Also, we can make a real-time translator in which we can speak out and the code will convert the language. This will require some more digging in the topic, so we will leave it for some other day.
For now, we will be building a simple language translator.
#Importing the library packageimport goslate#Taking input from usertext = input("Enter the text:\t")#Calling the goslate functiongs = goslate.Goslate()#Translating the text to our preferred languagetrans = gs.translate(text,'hi')#Displaying the outputprint(trans)
So, the above code does the required work for us. It takes an English sentence and translates into Hindi. You can choose any language of your choice.
So, with the above four Python Projects, I hope you learnt something and will make better versions of these simple projects with much more options and in-depth analysis.
Take these projects as starter codes and use them to build better projects. You can also create many more Python projects once you develop the right skills. So, keep practising and keep going forward.
After you have finished reading this one, I would like to suggest a few more great stories to read which offers good knowledge and helps you learn new things.
shubhamstudent5.medium.com
medium.com
medium.com
shubhamstudent5.medium.com
towardsdatascience.com
Thanks for reading the article. I hope you liked the article.