Log in / Register
Home arrow Computer Science arrow Python Programming Fundamentals
< Prev   CONTENTS   Next >

1.3 Writing Your First Program

To try out the installation of your IDE and Python you should write a program and run it. The traditional first program is the Hello World program. This program simply prints “Hello World!” to the screen when it is run. This can be done with one statement in Python. Open your IDE if you have not already done so. If you are using Windows you can select it by going to the Start menu in the bottom left hand corner and selecting All Programs. Look for Wing IDE 101 under the Start menu and select it. If you are using a Mac, go to the Applications folder and double-click the Wing IDE icon or click on it in your dock if you installed the icon on your dock. Once you've done this you will have a window that looks like Fig. 1.8.

In the IDE window you go to the File menu and select New to get a new edit tab within the IDE. You then enter one statement, the print statement shown in Fig. 1.8 to print Hello World! to the screen. After entering the one line program you can run it by clicking the green debug button (i.e. that button that looks like a bug) at the top of the window. You will be prompted to save the file. Click the Save Selected Files button and save it as You should then see Hello World! printed at the bottom of the IDE window in the Debug I/O tab.

The print statement that you see in this program prints the string “Hello World!” to standard output. Text printed to standard output appears in the Debug I/O tab in the Wing IDE. That should do it. If it doesn't you'll need to re-read the installation instructions either here or on the websites you downloaded Python and Wing IDE from or you can find someone to help you install them properly. An IDE is used in examples and practice exercises throughout this text so you'll need a working installation of an IDE and Python to make full use of this text.

1.4 What Is a Computer?

So you've written your first program and you've been using a computer all your life. But, what is a computer, really? A computer is composed of a Central Processing

Fig. 1.8 The Wing IDE

Unit (abbreviated CPU), memory, and Input/Output (abbreviated I/O) devices. A screen is an output device. A mouse is an input device. A hard drive is an I/O device. The CPU is the brain of the computer. It is able to store values in memory, retrieve values from memory, add/subtract two numbers, compare two numbers and do one of two things depending on the outcome of that comparison. The CPU can also control which instruction it will execute next. Normally there are a list of instructions, one after another, that the CPU executes. Sometimes the CPU may jump to a different location within that list of instructions depending on the outcome of some


That's it. A CPU can't do much more than what was described in the previous paragraph. CPU's aren't intelligent by any leap of the imagination. In fact, given such limited power, it's amazing how much we are able to do with a computer. Everything we use a computer for is built on the work of many, many people who have built layers and layers of programs that make our life easier.

The memory of a computer is a place where values can be stored and retrieved. It is a relatively fast storage device, but it loses its contents as soon as the computer is turned off. It is called volatile store. The memory of a computer is divided into different locations. Each location within memory has an address and can hold a value. Figure 1.9 shows the contents of memory location 100 containing the number 48.

The hard drive is non-volatile storage or sometimes called persistent storage. Values can be stored and retrieved from the hard drive, but it is relatively slow compared to the memory and CPU. However, it retains its contents even when the power is off.

In a computer, everything is stored as a sequence of 0's and 1's. For instance, the string 01010011 can be interpreted as the decimal number 83. It can also represent the capital letter 'S'. How we interpret these strings of 0's and 1's is up to us. We









Fig. 1.9 Conceptual view of a computer

can tell the CPU how to interpret a location in memory by which instruction we tell the CPU to execute. Some instructions treat 01010011 as the number 83. Other instructions treat it as the letter 'S'.

One digit in a binary number is called a bit. Eight bits grouped together are called a byte. Four bytes grouped together are called a word. 210 bytes are called a kilobyte (i.e. KB). 210 kilobytes are called a megabyte (i.e. MB). 210 megabytes are called a gigabyte (i.e. GB). 210 gigabytes are called a terabyte (i.e. TB). Currently memories on computers are usually in the 1–8 GB range. Hard Drives on computers are usually in the 500 GB to 2 TB range.

Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >
Business & Finance
Computer Science
Language & Literature
Political science