From a simple rolling dice simulator all the way to a product review sentiment analyzer, learn how Python can be leveraged to build fun and creative projects

If you were to ask some tech gurus about a programming language that is powerful enough to develop a lot of creative projects, and at the same time is easy and intuitive, what do you think a common answer would be?

Yep, that’s right — Python!

Besides being simple and easy to learn, Python can be used for a wide range of fun and awesome applications like Web Development, Data Science, Automation, and Artificial Intelligence.

Python is one of the most popular languages in the world for making cool personal projects, so why not join in the fun by trying out these fun and impressive project ideas that you can make at home?

The Python Bible™ | Everything You Need to Program in Python

Last Updated April 2021

• 74 lectures
• Beginner Level
4.6 (44,751)

Build 11 Projects and go from Beginner to Pro in Python with the World’s Most Fun Project-Based Python Course! | By Ziyad Yehia, Internet of Things Academy

Ideas for Beginner Python Developers

1. Rolling Dice Simulator

Ever encountered a situation where you called your friends over for board games, just to realize that you’ve lost the dice?

Well, worry no more! You can use Python to replace your flaky dice, and here’s how.

The outcome of a dice roll is nothing more than a random number between 1 and 6.

To generate a random number with python, you just need to import the `randint’ function from python’s built-in ‘random’ module.

The randint function works by generating a random whole number in a given range.

Because we want numbers between 1 and 6 for our dice, we simply give the randint function a minimum value of 1 and a maximum value of 6, and print the value we get to the screen.

``````# Importing the 'random' package and 'randint' module
from random import randint

# Let's roll!
roll = randint(1,6)

print('You rolled a ', roll)``````

Output:

``You rolled a 6``

Voila, there you have it! Easy, right?

Each time you run the script, it will generate a random number between 1 and 6, exactly like a dice would.

So, the next time your friends come over, you can show them this fancy tool and impress them. Or, at the very least save the game night from being ruined by flaky dice.

2. Rock, Paper, Scissors

We all have fond memories of playing this game at some point in our lives. While some play it for sheer fun, others play it to settle seemingly unsolvable political disputes.

What if I told you even this could be replicated in Python? That’s right: python-based politics.

The basis of this game is that ‘Rock’ beats ‘Scissors’; ‘Scissors’ beat ‘Paper’; and ‘Paper’ beats ‘Rock’.

If you were to look at it from an algorithmic point of view, this game is basically a set of if-then conditions. If both parties pull the same hand, then it is a draw. If one party pulls out rock and the other party pulls out paper, then rock wins; and so on.

In Python this can be easily coded using the ‘if’ and ‘elif’ statements. This is a prime example of how Python’s English-like syntax helps developers convert their ideas into code.

This makes the most sense when playing against a computer. Once you decide your move, you use the random function to make the computer pick one of ‘Rock’, ‘Paper’ or ‘Scissors’. The logic I just mentioned can then be used to decide the winner.

3. Desktop Notifier

Wouldn’t it be wonderful if you are working on your laptop and get a notification reminding you of a task which was running in the background and needed your attention? Or say, news on the current price of a certain stock you wished to monitor. Or perhaps, a simple reminder to drink water.

It shouldn’t come off as a surprise that we can indeed use Python to build such a notifier in minutes.

For developing this, we need to use the ‘py-notifier’ package. You can easily install this from command prompt/terminal by typing the following code:

``pip install py-notifier``

If you’re on windows, you’ll also need to install the win10toast package, like so:

``pip install win10toast``

Pynotifier includes everything you need to send push notifications to your desktop and you can set the title, description text, and also control how long the notification stays on your screen

By writing just a few lines of code, we are done with this app in no more than a few minutes.

``````from pynotifier import Notification
title='It worked!',
description='Like, OMG!',
duration=5,
).send()``````

Here are the results:

Ideas for Intermediate Python Developers:

4. Countdown + Alarm

While working, we often get so absorbed in the current task at hand (or youtube videos) that we tend to forget the time. Having a countdown timer can come in handy in such situations. Yes, we do have the app on our smartphones, but won’t it be cool to develop our own? Plus, we can use building this project as an excuse to procrastinate!

Python’s ‘time’ package makes this easy. We create a function which would take the time to be counted as its argument; and the ‘sleep’ function in the ‘time’ package will make sure the program waits 1 second before counting down.

``````import time
def countdown(t):
while t:
mins, secs = divmod(t, 60)
timeformat = '{:02d}:{:02d}'.format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
t -= 1
print('Goodbye!')

countdown(15) # This will create a 15-second timer.``````

Challenge: To put the cherry on the top, you can integrate this with the desktop notifier project mentioned above as well as python’s alarm module to get an alarm to go off as soon as the timer goes down to zero.

And there you go, not only do you have a cool timer app, but also you have an alarm clock to remind you of the hard deadline (that’s probably now much closer).

5. Tic Tac Toe

Let’s get back to games. I am sure we’ll all agree this was one of the best games we played as children (and even adults, haha).

It is a simple two-player game which can be played with pen and paper. The rules are simple: there’s basically a 3×3 square grid, in which the two players mark ‘X’ and ‘O’ on their respective turns. The first player to create a horizontal, vertical, or diagonal line with their marks, wins.

To implement this in Python, you can use the ‘Pygame’ library to design the game board and display the ‘X’s and ‘O’s. The main algorithm will consist of if-else conditions pertaining to the horizontal, vertical, and diagonal lines. Once these are met, the game stops and we have a winner.

Challenge: Try building this in a text format first, and then try to build it using a graphical package such as pygame.

6. Document Translator

Are you fascinated by Google Translate, and how it has facilitated the translation of words in any language at the click of a button? It’s basically magic. Well, now you can do magic too — with python!

All you need to do is install the googletrans library. You can do this at a command prompt/terminal window like so:

``pip install googletrans``

It’s kind of amazing how easy this is to use. Take a look:

``````from googletrans import Translator
translator = Translator()
output = translator.translate('wie hiesen sie?', dest='en')
print(output.text)``````
``"What's your name?"``

Challenge: Seeing as this is an intermediate project, try to get this script to read a certain file, translate it into a language of your choice, and then write the output to another file.

Tip: Check out python’s inbuilt file module.

7. Job Search Web Scraper

Searching for jobs online can become a tricky task, especially with so many jobs out there that look so similar. It can get tiresome to visit the many job portals out there, and browse through each of their many pages, and read every single job description.

Wouldn’t it be great if you could pull out all this information automatically into a spreadsheet, and look at it at your inconvenience? This is where the magic of Web Scraping and Python modules such as ’BeautifulSoup’ come in.

Web Scrapers send http requests to web pages and send you back all the information on the desired webpage (called a response). With some pattern matching of the classes in the response, you can locate the parts of the web page where the job titles, job descriptions, etc. are stored. You can then structure all of this information in a tidy dataset and save it in an excel spreadsheet.

First, you need to install the required libraries from a command prompt/terminal:

``pip install beautifulsoup4 pandas requests``

And then import them in the script:

``from bs4 import BeautifulSoupimport pandas as pdimport requests``

We now begin to build a web scraper to find analyst jobs in London. You’d now be amazed how you can do this in just a few lines of code:

``````url = "https://www.indeed.co.uk/jobs?q=analyst&l=london&fromage=last&sort=date"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
job_soup = soup.find(id="resultsCol")
job_elems = job_soup.find_all('div', class_='jobsearch-SerpJobCard')``````

Note that this did require some fiddling around to find out what elements on the page to extract, but that’s pretty straightforward if you know some basic HTML and right-click the web page and use the “inspect element” feature of your browser.

After the scraper is setup, let’s now extract some jobs and store them in a neat dataset:

``````job_titles = []
company_names = []
for i in range(len(job_elems)):
job = job_elems[i].find('h2', class_='title').text.strip().split('\n')[0]
company = job_elems[i].find('span', class_='company').text.strip()
job_titles.append(job)
company_names.append(company)
jobs_df = pd.DataFrame({'Job':job_title, 'Company': company_name})print(jobs_df)``````

The output looks  something like this:

Challenge: Try to also take the job’s individual page link, and try to write the data to an excel file Tip: You can write to excel using the pandas library that we have already imported!

8. Invoice Recognition

Keeping track of spending is important, and almost every business has the problem of keeping track of receipts and invoices.

Given the huge amount of such invoices, it can become a bit of a nightmare to store and search the information manually. Not only is it time-consuming and hard work, but imagine how error-prone it would be if an actual human is to transfer those tiny bits of information from the invoice to the computer. Python to the rescue again!

The development of popular modules, ‘Tesseract’ and ‘OpenCV’ has facilitated automated scanning of such documents. The deep learning algorithms embedded in these modules not only give us the accurate text, but also their coordinates within the dimensions of the invoice. This further allows us to process the plain text returned by these modules.

Let’s do a quick install of the ‘pytesseract’ package from our command line/terminal:

``pip install pytesseract``

Once installed, the few lines of code below allow you to scan the image of your choice.

``````# import libraries
try:
from PIL import Image
except ImportError:
import Image
import pytesseract

# This is the full path to your tesseract executable
pytesseract.pytesseract.tesseract_cmd = r'C:/Program Files/Tesseract-OCR/tesseract.exe'

#Perform OCR using Tesseract
print(pytesseract.image_to_string(Image.open('dummy.JPG')))``````

Let’s see the results:

Challenge: Try to build a receipt scanning app that you can use with your laptop’s webcam to enter data receipt data into a spreadsheet! Bonus points if you make the app go “beep” every time it scans something!

9. Product Review Scraper + Sentiment Analysis

What’s the first thing you’d do before watching a movie someone suggested to you, or buying something on Amazon? Check out reviews, right?

But then, you only see the top few reviews on the first page, and it becomes pretty boring browsing through the subsequent pages for more reviews. What if only the good reviews are there in the first couple of pages? As you browse through pages, how do you keep track of whether the reviews were positive or negative?

Well, web scraping, which we discussed above can help us retrieving all the reviews for a given product with ease.

Given this data, we can now use python’s TextBlob library to find out the sentiment in one single line of code. Textblob can return a polarity score between -1 (very negative) and 1 (very positive). Having found this value for all the reviews, you can take an average to find the overall sentiment of the movie.

First, you will need to install python’s TextBlob module like so from a command prompt or terminal:

``pip install textblob``

Now you can use TextBlob to computer polarity scores for various pieces of text:

``````from textblob import TextBlobreview1 = 'The movie was very nice.'review2 = 'Some scenes were good, but the story was boring.'
polarity_score1 = TextBlob(review1).sentiment.polaritypolarity_score2 = TextBlob(review2).sentiment.polarity
print('Polarity Score 1: ', polarity_score1)print('Polarity Score 2: ', polarity_score2)``````

Output:

``````Polarity Score 1: 0.78
Polarity Score 2: -0.15``````

Challenge: Try downloading the first 100 reviews that contain text for a product on amazon and computing their polarity scores. Then, calculate the average. Finally, see how well this matches with the product’s star value. Based on a 5-star rating system, a good match will see a product with an average polarity score of 0-0.2 as 1 star, a polarity score of 0.2-0.4 as 2 stars, 0.4-0.6 as 3 stars, and so on.

Wrapping Up

Phew! By now, I am sure you’ve realized the magnificence and power of Python. The importance of hands-on practice cannot be emphasized enough, and I really hope that you’re roaring with energy to build some of these projects on your own (if not all of them!).

If you enjoyed this article, I invite you to check out my Python Bible course on Udemy. The Python Bible is perfectly tailored to the needs of beginners, and it includes lots of fun projects to build up your python skills.

Thanks for reading and have a wonderful python-day, you beautiful people!

Page Last Updated: September 2020

Top courses in Python

The Modern Python 3 Bootcamp
Colt Steele
4.7 (27,725)
Python for Data Science and Machine Learning Bootcamp
Jose Portilla
4.6 (126,518)
Bestseller
Machine Learning A-Z™: Python & R in Data Science [2023]
Kirill Eremenko, Hadelin de Ponteves, Ligency I Team, Ligency Team
4.5 (165,788)
Python for Financial Analysis and Algorithmic Trading
Jose Portilla
4.4 (16,977)
Bestseller
Automated Software Testing with Python
Jose Salvatierra, Teclado by Jose Salvatierra
4.5 (4,346)
Learn Python & Ethical Hacking From Scratch
Zaid Sabih, z Security
4.6 (17,135)
Python Network Programming for Network Engineers (Python 3)
David Bombal, Experts with David Bombal
4.6 (8,007)

Python students also learn

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.