Challenge: Write a simple program using Python.
What is Python?
Python is a remarkably powerful dynamic programming language that is used in a wide variety of application domains. Python is often compared to Tcl, Perl, Ruby, Scheme or Java. Some of its key distinguishing features include:
- very clear, readable syntax
- strong introspection capabilities
- intuitive object orientation
- natural expression of procedural code
- full modularity, supporting hierarchical packages
- exception-based error handling
- very high level dynamic data types
- extensive standard libraries and third party modules for virtually every task
- extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
- embeddable within applications as a scripting interface
This is a simple script I wrote to calculate the first 16 powers of 2 including 0.
a = 0 b = 1 while a < 17: print b, a, b = a + 1, b * 2
In the print statement having the comma after b causes the next item printed to be on the same line. This line of code a, b = a + 1, b * 2 is a multiple assignment that assigns a + 1 to a and b * 2 to b.
This code snippet form KYA will sort a list.
# Bubble Sort # KYA # 7-20-08 def bubbleSort(theList, max): for n in range(0,max): #upper limit varies based on size of the list temp = 0 for i in range(1, max): #keep this for bounds purposes temp = theList[i] if theList[i] < theList[i-1]: theList[i] = theList[i-1] theList[i-1] = temp
For those of you who don't know what to do with Python, here's some ideas:
- A number guessing game
- Printing out the roll of dice
- Create a random password generator that generates a password with a certain number of letters and numbers
- A file handler that does something useful (such as remove executable properties on all files in the parent directory and below)
- Advanced - Create a Twitter application using python-twitter or Python Twitter Tools
- Advanced - Create a simple game demo using pygame
- Python Website
- Python Documentation
- Python Beginner‘s Guide
- The Python Tutorial
- Python Twitter Tools
We also have a Perl & Python forum and Snippets area as well as a couple Python Tutorials if you're interested.
How To Get Started:
Installing python on windows is no harder than installing any other piece of software, go to http://python.org/download/ and get the appropriate package. On linux it's likely already included, but python3 will need to be installed explicitly, most distros have a package named "python3", so go ahead and grab that (source is always available if you run an odd-ball distro). If you need help, just ask google.
For more information on installing Python you can visit this link.
Submit Your Challenge:
When you've completed the challenge, reply to this thread with a .zip/link/code/etc. of what you did.
Post questions in our Perl & Python Forum.