How to write and run a Python programYou have basically three choices to develop and test a Python program: Show
The IPython notebook is briefly descried in the section Writing IPython notebooks, while the other two options are outlined below. The need for a text editorSince programs consist of plain text, we need to write this text with the help of another program that can store the text in a file. You have most likely extensive experience with writing text on a computer, but for writing your own programs you need special programs, called editors, which preserve exactly the characters you type. The widespread word processors, Microsoft Word being a primary example, are aimed at producing nice-looking reports. These programs format the text and are not acceptable tools for writing your own programs, even though they can save the document in a pure text format. Spaces are often important in Python programs, and editors for plain text give you complete control of the spaces and all other characters in the program file. Text editorsThe most widely used editors for writing programs are Emacs and Vim, which are available on all major platforms. Some simpler alternatives for beginners are
We may mention that Python comes with an editor called Idle, which can be used to write programs on all three platforms, but running the program with command-line arguments is a bit complicated for beginners in Idle so Idle is not my favorite recommendation. Gedit is a standard program on Linux platforms, but all other editors must be installed in your system. This is easy: just google the name, download the file, and follow the standard procedure for installation. All of the mentioned editors come with a graphical user interface that is intuitive to use, but the major popularity of Emacs and Vim is due to their rich set of short-keys so that you can avoid using the mouse and consequently edit at higher speed. Terminal windows To run the Python program, you need a terminal window. This is a window where you can issue Unix commands in Linux and Mac OS X systems and DOS commands in Windows. On a Linux computer, You must first move to the right folder using the Using a plain text editor and a terminal window
Spyder
Spyder is a graphical application for developing and running Python programs, available on all major platforms. Spyder comes with Anaconda and some other pre-built environments for scientific computing with Python. On Ubuntu it is conveniently installed by The left part of the Spyder window contains a plain text editor. Click in this window and write You may continue with more advanced statements involving graphics: import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 4, 101) y = np.exp(-x)*np.sin(np.pi*x) plt.plot(x,y) plt.title('First test of Spyder') plt.savefig('tmp.png') plt.show() Choosing Run - Run now leads to a separate window with a plot of the function \( e^{-x}\sin (\pi x) \). Figure 64 shows how the Spyder application may look like. Figure 64: The Spyder Integrated Development Environment. The plot file we generate in the above program, A convenient feature of Spyder is that the upper right window continuously displays documentation of the statements you write in the editor to the left. Is a person with the training and skill needed to design create and test computer programs?A programmer, or software developer, is a person with the training and skills necessary to design, create, and test computer programs. Computer programming is an exciting and rewarding career.
Is a program that both translates and executes the instructions in a program?An interpreter is a program that both translates and executes the instructions in a high- level language program.
Is the part of the computer that actually runs programs and is the most important component in a computer?Central Processing Unit (CPU)
The CPU is the brain of a computer, containing all the circuitry needed to process input, store data, and output results. The CPU is constantly following instructions of computer programs that tell it which data to process and how to process it.
What is the main reason for using secondary storage?Secondary storage is needed to keep programs and data long term. Secondary storage is non-volatile , long-term storage. Without secondary storage all programs and data would be lost the moment the computer is switched off.
|