943,917 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 173345
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 9th, 2005
9

Projects for the Beginner

Expand Post »
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.

There is also a thread Advanced and Intermediate Projects , see:
http://www.daniweb.com/forums/thread257510.html
Last edited by vegaseat; Feb 4th, 2010 at 9:02 am.
Similar Threads
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 9th, 2005
7

Re: Projects for the Beginner

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!
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 9th, 2005
2

Re: Projects for the Beginner

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?"
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 9th, 2005
4

Re: Projects for the Beginner

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 ...
python Syntax (Toggle Plain Text)
  1. # goofy sentence generator
  2.  
  3. import random
  4.  
  5. def make_sentence(part1, part2, part3, n=1):
  6. """return n random sentences"""
  7. # convert to lists
  8. p1 = part1.split('\n')
  9. p2 = part2.split('\n')
  10. p3 = part3.split('\n')
  11. # shuffle the lists
  12. random.shuffle(p1)
  13. random.shuffle(p2)
  14. random.shuffle(p3)
  15. # concatinate the sentences
  16. sentence = []
  17. for k in range(n):
  18. try:
  19. s = p1[k] + ' ' + p2[k] + ' ' + p3[k]
  20. s = s.capitalize() + '.'
  21. sentence.append(s)
  22. except IndexError:
  23. break
  24. return sentence
  25.  
  26. # break a typical sentence into 3 parts
  27. # first part of a sentence (subject)
  28. part1 = """\
  29. a drunken sailor
  30. a giggling goose
  31. the yearning youth
  32. the obese ostrich
  33. this mean mouse
  34. the skinny sister"""
  35.  
  36. # middle part of a sentence (action)
  37. part2 = """\
  38. jumps over
  39. flies over
  40. runs across
  41. openly ogles
  42. twice tastes
  43. vomits on"""
  44.  
  45. # ending part of a sentence (object)
  46. part3 = """\
  47. a rusty fence
  48. the laughing cow
  49. the weedcovered backyard
  50. the timid trucker
  51. the rancid old cheese
  52. the jolly jelly"""
  53.  
  54. print '-'*60
  55.  
  56. sentence = make_sentence(part1, part2, part3, 3)
  57. for item in sentence:
  58. print item
  59. print '-'*60
  60.  
  61. """
  62. a typical result -->
  63. A drunken sailor flies over the laughing cow.
  64. The obese ostrich runs across the weedcovered backyard.
  65. This mean mouse openly ogles the jolly jelly.
  66. """
Click on "Toggle Plain Text" so you can highlight and copy the code to your editor without the line numbers.
Last edited by vegaseat; Mar 1st, 2007 at 4:17 pm. Reason: missing lines
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 9th, 2005
1

Re: Projects for the Beginner

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 9th, 2005
1

Re: Projects for the Beginner

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 9th, 2005
1

Re: Projects for the Beginner

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 13th, 2005
1

Re: Projects for the Beginner

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.
Attached Files
File Type: zip DictionaryE.zip (286.9 KB, 1446 views)
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 13th, 2005
0

Re: Projects for the Beginner

Translate from one language to another. For instance from English to Texan.

Hint, one approach would be the one used in the Python code snippet at:
http://www.daniweb.com/code/snippet395.html
Last edited by vegaseat; Sep 15th, 2006 at 1:07 am.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 13th, 2005
2

Re: Projects for the Beginner

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.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Message:
Previous Thread in Python Forum Timeline: For loop, for creating buttons
Next Thread in Python Forum Timeline: How to execute a command with arguments





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC