| | |
Projects for the Beginner
![]() |
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 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.
May 'the Google' be with you!
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?
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?
May 'the Google' be with you!
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.
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.
Vi veri veniversum vivus vici
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.
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.
Vi veri veniversum vivus vici
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.
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.
Vi veri veniversum vivus vici
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.
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.
May 'the Google' be with you!
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.
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.
May 'the Google' be with you!
![]() |
Similar Threads
- Ideal project for a beginner? (Python)
- Hep finding C++ Projects (Python)
- Help finding C++ Projects (C++)
- New task from Projects for the beginner: (Python)
Other Threads in the Python Forum
- Previous Thread: What does "steals" a reference mean?
- Next Thread: wondering some things about lists
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book builtin calculator change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event file float format function google homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin prime programming py2exe pygame pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax table terminal text textarea threading time tlapse trick tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






