Here is a classic Chomsky sentence writer. Your mission will be to customize the data using for instance some of your boss's latest memos.

An aid to writing linguistic papers in the style of Noam Chomsky.
It is based on selected phrases taken from actual books and articles
written by the great master.  Upon request, it assembles the phrases
in the elegant stylistic patterns that Chomsky was noted for.

You are encouraged to add more patterns.

To generate n sentences of linguistic wisdom, type ...
chomsky(5) generates about half a screen of linguistic truth

modified to work with Python2 and Python3

import textwrap
import random
from itertools import chain, islice

def chomsky(n=1, line_length=72):
    put it all together Noam Chomsky style, n = number of sentences
    parts = []
    for part in (leadins, subjects, verbs, objects):
        phrase_list = [x.strip() for x in part.splitlines()]
    output = chain(*islice(zip(*parts), 0, n))
    return textwrap.fill(' '.join(output), line_length)

# 'lead ins' to buy some time ...
leadins = """\
To characterize a linguistic level L,
On the other hand,
This suggests that
It appears that
We will bring evidence in favor of the following thesis:
To provide a constituent structure for T(Z,K),
From C1, it follows that
Note that
Of course,
Suppose, for instance, that
With this clarification,
We have already seen that
By combining adjunctions and certain deformations,
I suggested that these results would follow from the assumption that
However, this assumption is not correct, since
In the discussion of resumptive pronouns following (81),
So far,
For one thing,
Summarizing, then, we assume that
A consequence of the approach just outlined is that
On our assumptions,
It may be, then, that
It must be emphasized, once again, that
Let us continue to suppose that
Notice, incidentally, that """

# subjects chosen for maximum professorial macho ...
subjects = """\
the notion of level of grammaticalness
a case of semigrammaticalness of a different sort
most of the methodological work in modern linguistics
a subset of English sentences interesting on independent grounds
the natural general principle that will subsume this case
an important property of these three types of EKC
any associated supporting element
the speaker-listener's linguistic intuition
the descriptive power of the base component
the earlier discussion of deviance
this analysis of a formative as a pair of sets of features
this selectionally introduced contextual feature
a descriptively adequate grammar
the fundamental error of regarding functional notions as categorial
relational information
the systematic use of complex symbols
the theory of syntactic features developed earlier"""

# verbs chosen for autorecursive obfuscation ...
verbs = """\
can be defined in such a way as to impose
suffices to account for
cannot be arbitrary in
is not subject to
does not readily tolerate
raises serious doubts about
is not quite equivalent to
does not affect the structure of
may remedy and, at the same time, eliminate
is not to be considered in determining
is to be regarded as
is unspecified with respect to
is, apparently, determined by
is necessary to impose an interpretation on
appears to correlate rather closely with
is rather different from"""

# objects selected for profound sententiousness ...
objects = """\
problems of phonemic and morphological analysis.
the traditional practice of grammarians.
a stipulation to place the constructions into these categories.
a descriptive fact.
a parasitic gap construction.
the extended c-command discussed in connection with (34).
the system of base rules exclusive of the lexicon.
irrelevant intervening contexts in selectional rules.
nondistinctness in the sense of distinctive feature theory.
a general convention regarding the forms of the grammar.
an abstract underlying order.
an important distinction in language use.
the strong generative capacity of the theory."""

# test it ...
print(( chomsky(1) ))

print(( '-'*70 ))

print(( chomsky(5) ))

Edited by vegaseat: eg


Don't know if it's been suggested, but if you're into wanting to make video games, try to create a text version of Battleship, Tic-Tac-Toe, or any other game you can think of. Then, create an AI to play with you. And make it really good, and hard to beat. It's harder than it sounds.


Here is the beginning of a word based calculator, that you can explore and expand past its simple stage ...

# start of a text based calculator

num_dict = {
'one' : '1',
'two' : '2',
'three' : '3',
'four' : '4',
'five' : '5',
'six' : '6',
'seven' : '7',
'eight' : '8',
'nine' : '9'

op_dict = {
'plus' : '+',
'times' : '*',
'equals' : '='

# combine the the above dictionaries in mydict
mydict = {}

text = 'seven plus two equals'
calc = ""
for term in text.split():
    if term == 'equals':
        result = eval(calc)
    elif term in mydict:
        calc += str(mydict[term])

print "%s = %s" % (calc, result)

"""result -->
7+2 = 9

# optional display of the result in text ...
# need to reverse key and value of the number dictionary
swap_dict = dict((v, k) for (k, v) in num_dict.items())

if str(result) in swap_dict:
    print "%s %s" % (text, swap_dict[str(result)])  

"""result -->
seven plus two equals nine

Also, for a Number to Word Converter see:

Edited by vegaseat: n2w


A translate one language to another project.
Here is a simpleminded start ...

# translate English to Spanish word by word
# let's first build a simple English to Spanish dictionary ...

eng = "one, two, three, four, five, six, seven, eight, nine, ten"

# after  translate.google.com  English to Spanish translation
esp = "uno, dos, tres, cuatro, cinco, seis, siete, ocho, nueve, diez"

# create a list of english words and a list of spanish words
eng_list = eng.split(", ")
esp_list = esp.split(", ")

# create the english_word:spanish_word dictionary
eng2esp_dict = {}
k = 0
for eng_word in eng_list:
    eng2esp_dict[eng_word] = esp_list[k]
    k += 1
print eng2esp_dict

"""my result (made pretty), order is hash order -->
'seven': 'siete', 
'ten': 'diez', 
'nine': 'nueve', 
'six': 'seis', 
'three': 'tres', 
'two': 'dos', 
'four': 'cuatro', 
'five': 'cinco', 
'eight': 'ocho', 
'one': 'uno'

# simplified example text to translate word by word
eng_phrase = "one six nine"
esp_phrase = ""
for word in eng_phrase.split():
    default_word = "--" + word + "--"
    esp_phrase += eng2esp_dict.get(word, default_word) + " "

print( esp_phrase )  # uno seis nueve

# test default
eng_phrase = "one six eleven"
esp_phrase = ""
for word in eng_phrase.split():
    default_word = "--" + word + "--"
    esp_phrase += eng2esp_dict.get(word, default_word) + " "

print( esp_phrase )  # uno seis --eleven--

Improve the code by increasing the dictionary, handle lower and upper case, handle punctuation marks and so forth.

Edited by vegaseat: eng2esp trans


Let's say you have one real nice 2010 picture calendar, and want to use a Python program to calculate in which future years you can reuse this calendar.


Here is a way to create a simple console bar graph:

# a very simple horizontal bar graph

data = [20, 15, 10, 7, 5, 4, 3, 2, 1, 1, 0]

for i in data:
    print("#" * i)

""" my output -->


How can you add the data value to the end of each bar, and how can you make this a vertical bar graph?

Edited by vegaseat: OP's request


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:
You need to be able to freeze the graphics and save it as an image file.

Some beginner graphics even easier than PyGame can be found using the myro library, or zelle's graphics.



Given this real world data below, can you write a Python program to figure out why paula hates abby?

data_str = """\
mary loves fred
fred hates paula
paula loves harry
harry hates mary
harry loves abby
abby hates john
karen loves john
john hates fred
fred loves harry
paula hates abby

Create a file split/join program in python. The first idea about this came to me from programming python in which a very basic splitter/joiner is given. Extend the file splitter to use GUI for user convenience, CRC/MD5 for checksum and reliabilty and some other harder stuff like compression etc.

Edited by tushartyagi: n/a


Let's say you would be involved in making cylindrical metal cans (could happen!). Calculate the ratio of radius to height, to give you the largest volume for the least amount of metal sheet.

Votes + Comments

Extending the IRC post:

See what crazy things you could make your bot do. Like turn on an air freshener or text some ones cell phone.


What do you think the result of the mystery code is?

s1 = "cfe sapro h a encuhduo"
s2 = "ofei  esnwohsbe oge pn"

text = ""
for c1, c2 in zip(s1, s2):
    text += c1 + c2


How would you generate s1 and s2 from a given text?


These practices are very very nice. But could you please provide the best answers too?? By best I mean, the way that it is easiest and most efficient to do it with Python.

Editor: People need to actually work out these projects to best learn Python or programing in general. Some hints might be okay.

Edited by vegaseat: note


Write simple theatre booking system. Start off by just using the console, then possibly moving on to GUI. Similarly, start off storing your data in text files, then move on to using proper database modules. Don't put yourself under too much pressure either! Just have a simple system that lets you book or unbook seats. Then add features such as: multiple performances and ticket types (Adult, Child, Discount). Also, you could make a console-GUI, where you use ASCII characters to create squares for seats, with the seat numbers in them. Then, use [A][C][D} to show which seats are taken and by who.

Start simple. Don't have too many seats at the beginning. 3 rows of 5 max.
Sort out file storage. Data retrieval is important. Make sure you have a simple input output.
Use loops for loading the dater from a file. This means you can repeat many times.
Use loops elsewhere in your program to cut down on how much code you have.

Votes + Comments
nice idea

Write a simple database program. Start off by inputting data through the console, then make a GUI (Tkinter or wxPython). Make completely your own system! Write/read data to/from text files.

Start off with the vary basics. Just get a basic input output system going first. Don't worry about the program loop just yet. Just make sure that you can read and write data.
Keep your console GUI basic. It's only temporary, and, if there is too much clutter, it's hard to understand.
Use lots of loops so everything can be re-used. RECYCLE RECYCLE RECYCLE!!!

Edited by SgtMe: n/a


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
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.

This project was very useful to me, so just wanted to say thank you. I have implemented command line, GUI with both file as well as database versions using OracleXE and SQLite.


1. A recursive tic-tac-toe program that never loses (but can be drawn).
2. A rotating cube.
3. The eight queens puzzle solver.
4. The sliding block puzzle (the 8-puzzle).
5. Conway's The Game of Life (easy).
6. Finding the shortest route in a graph (map of Romania).
7. The Mandelbroit set and Julia sets.
8. The Game of Pong.
I have written all of these programs, and consequently have vastly improved my coding skills. But I would like to see other people's suggestions.

Votes + Comments
Good enough

take a program you made in the command line and add a GUI to it, or you could make a calculater to do multi-step equation at once


Create a battleship type game using
import random
to generate numbers. When they sink your ship they win!
(you could use use co-ordiantes (x/y) that have been randomly generaeted)


Gigasecond vs nanosecond

Your computer has worked so hard that you want to give it generous holiday of one second by replacing it in it's job. The computer calculates your program one operation per nanosecond, so you have little much job to do. How much real time must you spend in this job? Let's say that you can manage one operation per second. Consider the difference of floating point and integer numbers if you are using Python 2 to find the answer. Calculator will do also, but Python is capable calculator in command line if you say:

from __future__ import division # for Python 2
from math import *

Edited by pyTony: n/a


Write a Python program that displays this result:

1 * 8 + 1 = 9
12 * 8 + 2 = 98
123 * 8 + 3 = 987
1234 * 8 + 4 = 9876
12345 * 8 + 5 = 98765
123456 * 8 + 6 = 987654
1234567 * 8 + 7 = 9876543
12345678 * 8 + 8 = 98765432
123456789 * 8 + 9 = 987654321

Votes + Comments

x * y = 12345678987654321

... that is 1 to 9 and down again. Write a Python program that finds the integer values for x and y where x and y can be equal.

Edited by vegaseat: n/a


If you have simple English word like:

str1 = 'supercalifragilisticexpialidocious'

How would you form string that has every second letter in capital (upper case).

I do not know if it is appropriate to post a solution here. But I would like to have
feedback to see if my solution can be improved.

Thank you

Editor's note: Do not post solutions here, it would spoil things. Use a new thread in the regular Python forum for that, with an appropriate title of course.

Edited by vegaseat: spoil


I do not know if it is appropriate to post a solution here. But I would like to have
feedback to see if my solution can be improved.

Thank you

Editor's note: Do not post solutions here, it would spoil things. Use a new thread in the regular Python forum for that, with an appropriate title of course.

Thank you, that of course makes perfect sense.

Votes + Comments
thanks for following the rules

The parameters in Python function range(begin, end, step) take only integer values. Your mission is to write a function frange(begin, end, step) that allows you to use floating point values for its parameters. Test the new function thoroughly as comparing floating point numbers can give problems.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.