After you got the basics of Python under your belt, the best way to get a good knowledge of the language and improve your coding skills is to start on a project you are interested in. Maybe an image viewer, a slide show, computer generated random or fractal art, a database for your baseball cards, a story writer, ...

This sticky is dedicated to a list of just such projects.

If you know a good project, please post it here. If you have questions, start your own thread and don't clutter the sticky. Please do not post your answeres in here!

There is also a thread Advanced and Intermediate Projects , see:
http://www.daniweb.com/forums/thread257510.html

Editor's note:
Some of the earlier examples are written for Python2 and may contain print statements like
print 'hello'
For Python3 this has to be changed to
print('hello')

DerKleineDude commented: The beginner's tutorials are a big help. The posts are aways well written and easy to understand. +1
Ene Uran commented: nice idea +8
tushg commented: Great Work :) Vegaseat :) Could you please Help me My Python Pyramid is Not working http://www.daniweb.com/software-development/python/threads/438405/running-the-project-application-in-pyramid-python-is-not-working# +0

Start a code library. As time goes on you will collect code snippets, hints and tricks from all over the net. So why not use Python to store these cut and pasted pieces of code in a file.

Attach a title and a set of keywords to each snippet that allows you to search the file and retrieve the code easily. You might want to use just one file and keep appending, so you have to find a way to keep the snippets appart from each other within the file. I have done it with a list where the items were separated by a dotcode-marker, works well, but it may not be a good way.

You can search the file directly or load the file into a list to speed things up. I leave it up to you. Keep thinking!

A units of measurement converter. Think about all the things that are measured, like distance, area, volume, energy, weight, temperature, pressure and so on. Now think about the many units of measurement the people around the globe use, anything from rods, stones, pounds, inches, pints and liters. A rather long list.

Start simple, let's say just the distances and a few units. Get that to work, then add more. Google the net for conversion factors. How would you handle the information? Maybe a dictionary in Python. Are there any neat shortcuts?

Your program should answer questions like:
"How many inches in a meter?"
"How many milliliters in a pint?"
"How many acres in a square-mile?"
"How many pounds in a metric ton?"
"How many calories in a BTU?"

Construct a sentence generator. Write down a bunch of sentences. Now pick them apart into lists of nouns, verbs, adverbs, adjectives and so forth. Use these pieces and create new sentences more or less at random. Some of those will be silly, some utter nonsense, but some could be the start of poetry or a novel.

Just to get you started, here is a very simple sentence generator, that takes the three parts (subject, action, object) of a standard sentence, shuffles these parts and reassembles the sentence ...

# goofy sentence generator
 
import random
 
def make_sentence(part1, part2, part3, n=1):
    """return n random sentences"""
    # convert to lists
    p1 = part1.split('\n')
    p2 = part2.split('\n')
    p3 = part3.split('\n')
    # shuffle the lists
    random.shuffle(p1)
    random.shuffle(p2)
    random.shuffle(p3)
    # concatinate the sentences
    sentence = []
    for k in range(n):
        try:
            s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
            s = s.capitalize() + '.'
            sentence.append(s)
        except IndexError:
            break
    return sentence
 
# break a typical sentence into 3 parts
# first part of a sentence (subject)
part1 = """\
a drunken sailor
a giggling goose
the yearning youth
the obese ostrich
this mean mouse
the skinny sister"""
 
# middle part of a sentence (action)
part2 = """\
jumps over
flies over
runs across
openly ogles
twice tastes
vomits on"""
 
# ending part of a sentence (object)
part3 = """\
a rusty fence
the laughing cow
the weedcovered backyard
the timid trucker
the rancid old cheese
the jolly jelly"""
 
print '-'*60
 
sentence = make_sentence(part1, part2, part3, 3)
for item in sentence:
    print item
print '-'*60
 
"""
a typical result -->
A drunken sailor flies over the laughing cow.
The obese ostrich runs across the weedcovered backyard.
This mean mouse openly ogles the jolly jelly.
"""

Click on "Toggle Plain Text" so you can highlight and copy the code to your editor without the line numbers.

commented: I just get invalid syntax? +0

Why not a story teller? This is for the people that like writing stories. Ask the reader for a preference and the story starts in that direction. After a while ask for another preference and branch off along that preference.

The story evolves as directed by the reader. Great for adventure, mystery, romance and detective stories. Try it out on a short and simple story first. Who knows, it could be the next bestseller.

Computer art can be fun. PyGame might be the way to go here. Start out by drawing geometric designs using circles, ovals, lines, rectangles, lots of colors, put them in a loop that changes location, dimensions and colors.

To get an idea, look at the Python snippet at:
http://www.daniweb.com/code/snippet384.html
You need to be able to freeze the graphics and save it as an image file.

commented: I like that one +5

Make a physics problem solver. Sometimes called an equation solver.

Let's say you have a simple kinematics question:
Bertha jogs at an average 7 miles/hour, and her typical path is 2.5 miles long. How long will it take her.

You would let the user enter three items:
1. 7 miles/hour
2. 2.5 miles
3. ? hours
Your program should figure out the formula and fill the question mark.

A more advanced version would convert units and standardize them. So the user can enter:
1. 7 miles/hour
2. 17 minutes
3. ? feet

Once you get the hang of it, you can go from simple kinematics to dynamics, force, work, gravitation, magnetic flux, thermodynamics, quantum mechanics or to relativity.

Back in the dark ages when I took physics, I wrote one of these in a then brand-new language called C.

commented: Do you think you might still have the source code? +0

How would you write a simple spell checker for a text file?

Start simple and test your code. Attached is full English spelling dictionary file, one word on a line.

You just wrote a loop allowing the input of 20 names into a list. Alas, you made an error as you entered name number 17. Redesign your input loop, so you can correct the error easily without having to retype the previous 16 names.

commented: I try this +6

If you have a computer running Windows XP, then you can let the computer read text to you. For more details look at the Python snippet at:
http://www.daniweb.com/code/snippet326.html

You may load in a textfile and have it read, or simply read the results of a program out loud. You could help elderly people with failing eyesight, just keep thinking about uses.

Create a Video Poker game. You can use PyGame, Tkinter or wxPython to bring up the cards.

Attached is a graphics file containing all the cards and a few decks.

commented: I just chosen one random post to say thank you for this topic! I'm introducing myself to python and I appreciate very much all these stimulating exercises :) +1

Create a quiz game. Bring up a question and give four possible answers to pick from. Load the question and answers from a data file that also includes the code for the correct answer. Ask the questions in random order, and bring them up only once during the quiz. This can be a console program or dressed up in a GUI. Keep track of the correct answers given and evaluate the contestant at the end.

Attached is a typical data file. The lines are in the following order:
Correct answer's code letter
Question
Answer A
Answer B
Answer C
Answer D
...

The data file is a nice mix of questions with some humor thrown in. Double check the order, I might have goofed it up.

I program for a hobby, not a job (yet)
so i have a severe hunger for ideas, this thread is great and i would like to contribute,
Here are some ideas that might give someone in my situation something to do:

This is an extract from a song by pink floyd, in my opinion (and my friend who pointed it out to me) it looks like an algorithm (set of instructions) Doesn't take long but it's interesting to see how other people do it. Simple terms:
Turn this into code

All movement is accomplished in six stages,
and the seventh brings return.
The seven is the number of the young light.
It forms when darkness is increased by one.
Change return success.
Going and coming without error.
Action brings good fortune...
Sunset.

P.S You may say there's no point, it depends on how you look at it...

How about this:

Make a program that can generate random passwords
For example:

password length is fixed (or the user could enter a length)
number of characters in password is random (or again the user could specify)
number of digits in password is random (or user specified)
location of numbers/characters in password is random OR you could ask the user for a word then you could use that as a base and perhaps stick things on the end or begining or perhaps replace certain letters with numbers.

All up to you, it's just an idea

The game of chess was invented a few hundred years ago in India. The story has it, that the ruler of the area was so enchanted with the game, that he called the inventor to his palace, and asked him to name a gift.

The seemingly humble man asked the ruler to put a grain of rice on the first square of the chessboard, two grains of rice on the second and so on, doubling the grains each time until all 64 squares of the chessboard were filled.

The ruler was thinking about a full sack of rice and happily agreed. I didn't count it myself, but there are 32,000,000 grains of rice in a short ton (2,000 lbs). So do the calculation in Python and make a modern day comparison. Assume that a 50 foot rail car can carry 50 tons of rice.

How long would the train have be to carry the inventor's request?

Build a Memory Game. You shortly flash up a number of random words. Lets say three or five, and then ask the player to recall the words from a mutli choice answer. Do that a ten or twenty times and then rate the player.

They could be numbers too, but I think words are more fun.

Create a "one word at a time" text reader. Display the word in a large font for a certain amount of time. Set the font size so even grandma can read it. The time the word is displayed could be adjustable and might depend on the length of the word.

Sounds like a GUI program. If you have questions about setting font sizes, ask in the forum.

This project is similar to the "one word at a time" reader, except it functions like a flash card program. You display, let's say, a Spanish word for a certain amount of time and then the corresponding English word. What better to use than a Python dictionary? Then you can just read off the key followed by the value. This can be done as a simple console or a fancy shmenzy GUI program.

I hope the foreign characters display well. Otherwise you might have to stay with something more domestic.

How about this for something to do:

If you don't know what a ceaser cypher is then read this: http://library.thinkquest.org/C0126342/ceaser.htm

Make a simple program that encrypts and decrypts a simple sring into a ciphertext (my terminology is terrible, so bear with me)
example:

let's encrypt the string: 'ceaser'
using a ceaser shift of lets say...11
so to start with, the 'c' in ceaser would be shifted 11 places down the alphabet and end up as 'n':

a b (c) d e f g h i j k l m (n) o p q r s t u v w x y z
     ^ --------- 11 -------- ^

so basically you do that untill all the letters in the plaintext 'ceaser'
have been shifted 11 places along the alphabet:
'ceaser' == 'npldpc'

Note: if you reach the end of the alphabet and the count (11) is still not finished just go back to the start, ('s' and 'r' had to do that)

So once you've got that nailed, let the user input the string they want to convert and perhaps let them change the shift (number of places the letter is moved)
then simple enough if you want to decode/decrypt (whatever it's called) just stick a minus in front of the shift number (11 would = -11) so that it shifts backwards, simple as that ey?
hehehe have fun, and remember to be careful because symbols like: ,.'/"# ect are not in the alphabet so you might want to filter those out somehow.
Remember, it's your code...so do what you want with it.

happy coding,
a1eio

Whenever Pythonians gather, there is always a call for an executable file.

If you have Dev-C++, embedding Python is quite easy with the free Python Development Pak. Look at this C++ code snippet for more information:
http://www.daniweb.com/code/snippet387.html

The Python code has to be fed in strings (morsels) to the embedded interpreter, which actually uses a DLL like Python24.dll. I have played around with it, and found for instance that the for loops etc. have to be in one string (interpretable morsel) with a '\n' after the colon and proper indentation included.

For the masochists, this might be one way to create an executable Python file. Come to think of it, you could let a Python program do the nasty detailed work here! You might call it a Python to C++ translator.

Could be fun to experiment with it, start small and grow.

If you know a little about C++, take a look at this snippet:
http://www.daniweb.com/code/snippet97.html
It shows you how to access the soundchip on your Windows computer, and create all sorts of interesting sound effects. Will it be possible to do this with Python?

Write a simple calculator in Python. The program should accept an arithmetic expression from the command-line, then recursively parse it to produce a numerical value.

Like many programming projects, this one can be done in phases:

i) First, make the program parse only basic arithmetic. This means expressions that use only numbers and {+-*/%} (the percent sign means "modulo" - look it up if you don't know what that means).

ii) Next add in left and right parentheses.

iii) Next add in logs, exponents, absolute values, roots, and powers.

iv) Next add in the ability to solve expressions in terms of an unknown variable x, like in algebra. This part will be tricky!

Having coded up one of these guys before, let me tell you: it's not trivial, and it will make you change the way you think about parsing text/expressions.

If you want, you can also write a Tkinter GUI, but the challenging part is writing the calculator itself.

Somewhere upthread, vegaseat wrote about a sentence generator. Well, here's a twist: how about a sentence detector? In other words, can you write a program that can tell the difference between a body of text written by a human being and a body of text put together at random by a computer program?

We know that certain words are very likely to appear next to each other in the English language. For example, "English language," "next to," "for example," etc. The idea of the program is this: use urllib2 to parse a whole bunch of text from the results of random Google searches. Build a frequency table of word pairs. In other words, for every page you download, scan every two adjacent words on the page, and if the pair is new, add it to the table with a score equal to one, and otherwise, increase the score of the current entry in the table by one. A dictionary is probably best suited for this kind of data storage.

Then take some unknown text and score it using the frequency table. Again, scan every two adjacent words. If the pair is in the table, add its score to a running sum. If the pair is not in the table, subtract some arbitrary amount from the running sum. If the final sum is above some threshold, the program should say "I think this was made by a human being," and otherwise, the program should say "I think this is randomly-generated text."

Tweak your program until it can usually recognize the difference between a page off the Internet and a randomly-generated page. Better yet, see if you can get it to recognize the difference between an English language page off the Internet and a translated page in a foreign language.

You can, of course, make simplifications to the program, such as not counting numbers and detagging HTML pages.

Write a simple Python shell with a GUI. The shell should use Python functions whenever possible to make it as portable as it can be. This is another project that can be divided into phases:

i) Write the shell GUI. It should have a spot to enter commands and a scrollable output screen.

ii) Write the command parser. Have the shell recognize a limited subset of commands. If it sees those commands, it does the appropriate thing in Python - otherwise, it hands the command to the OS and reproduces the output on its screen. The list of commands the program should recognize are: cd, ls, clear, echo, exit, pwd, touch, rm, mkdir, rmdir, mv, cp, chmod, and ps. Most of these can be written in Python, but some may have to be redirected to the OS.

iii) Add a command history feature, so that pressing the up and down arrow keys lets you cycle through previously entered commands.

iv) Add the ability to run a command in the background by adding an & to it.

v) Add the ability to redirect output using > and >>.

vi) If you're feeling particularly ambitious, try to add tab-completion.

vii) If you're feeling very, very ambitious, try to add pipes!

I tried to do this before, and got stuck on (iii). I figured out that (using Tkinter) I needed threads to monitor up/down arrow keypresses, and I didn't have the energy to deal with threading at the time.

Take a look at:
http://www.daniweb.com/code/snippet395.html

This Python code snippet shows you how to replace multiple words in a text with matches in a dictionary. You could create a dictionary of slang words and make interesting texts.

This project takes wxPython or maybe Tkinter for GUI. Let the computer pick random color selecting random RGB value. The user has to match the color picking RGB (red, green, blue) values that colours a area next to the one of the computer color pick.

Similar to the color project but with frequency of a tone. The computer plays a tone with random audible frequency. The user tries to match this frequency. In a GUI project can use a slider. Buttons allow replay of either tone. At end evaluate closeness.

The code snippet called "Access Your PC Soundcard (Python)" at:
http://www.daniweb.com/code/snippet431.html
should give you the idea of how to select a musical instrument and play a short melody or a drum beat.

Write a quiz program that plays an instrument, and then let the user select from a multiple choice question which instrument was played.

If you have five dice, how often do you have to throw (average) the dice to get a hand of four sixes? Try with other poker hands too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.