Hardware Reference
In-Depth Information
Save the program as calculator.py , and run it by choosing Run Module from the Run
menu in IDLE or by typing python calculator.py at the terminal. Enter your user name
when prompted, and then provide the numbers that you want to calculate (see Figure 11-5)
until you get bored and type anything other than 1 to exit the program.
Figure 11-5:
Running
calculator
.py in IDLE
For more short programs that introduce important Python concepts, visit the oicial Python
Simple Programs wiki page at http://wiki.python.org/moin/SimplePrograms .
Example 3: Gaming with pygame
To illustrate the power of Python, this example creates a fully-functional arcade game based
on the classic game of Snake or Nibbles. To accomplish this, it uses an external Python library
called pygame .
Originally written by Pete Shinners, pygame is a collection of python modules designed to
add new functionality to the language—functionality speciically designed to make it easy to
write a game in Python. Each pygame module provides a function required by a modern
game, including sound, graphics and even networking support. Although it's possible to
write a game in Python without using pygame, it's a lot easier if you take advantage of the
code already written in the pygame library.
Search WWH ::




Custom Search