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!
Here is a simple number project: Prime numbers are positive integer numbers that are only divisible by itself or one. For example 2, 3, 5, 7, 11, 13, 17, are prime numbers, by convention 1 is not a prime number. Palindrome numbers are numbers in which the decimal digits are the same read left to right as they are read right to left. For example 77, 131, 1441. Your mission is to write a script…
You go to the store to buy a pound of Tshibo Java, your favorite coffee beans. There you are confronted with a dilema, the usual pound container costs $10. But the store offers you a choice, a new container with 33% more beans for $10 or the one pound container for a 33% discount. Write a Python program to figure out which deal is the best, or are they the same?
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
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
# concatinate the sentences
sentence = 
for k in range(n):
s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
s = s.capitalize() + '.'
# 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 = """\
# 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"""
sentence = make_sentence(part1, part2, part3, 3)
for item in sentence:
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.
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.
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.
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...
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.
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.
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.