Page 134 - Computer Science V2.0 Class 11
P. 134
Fig 5.4: Executing a Python instruction.
While entering the next command, we forgot to write an operator between the operands 7 and 5. So, IDLE points out
a syntax error (Fig 5.5).
Fig 5.5: Executing an erroneous instruction.
The Python Installer for Windows includes IDLE, by default.
5.5.2 Python Editor
To be able to save multiple instructions for future use in the form of a file (typically having a .py extension), we
use the Python Editor. To use the IDLE editor, follow the sequence of clicks: <File> <new>. A file containing Python
instructions is called a Python script or a Python program, and working with Python scripts is called working in the
script mode. To keep the Python script simple, we just type three instructions in the file:
The first line is an instruction for printing a line of exclamation marks.
The second line is an instruction to print a welcome message.
The third line is again an instruction for printing a line of exclamation marks.
Before proceeding further, let us note that the print() function is used to display the output produced on
the execution of a Python script on the standard output i.e., the monitor. The text to be displayed is enclosed
between the quotes (single quotes or double quotes). For example, in the first line, the text (also called a string)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!! is enclosed between the single quotes as '!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!'. This string could also be expressed as: "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!". However, in this book,
we prefer to use single quotes. It is pertinent to mention that the numerical values and numerical expressions are not
enclosed within quotes. We will learn more about print() in the upcoming chapters.
To save the file, again click on the menu bar, follow the click sequence <File> -> <Save As> and select the folder where
you want to save the file and choose a suitable name for the file. We have saved the file as 'F:/CBSE/class11/
ch5/welcome.py'. The saved script can be executed now or later.
Fig 5.6: Python Script
To execute a saved file, on the IDLE's menu bar, click on the <File> menu to open an existing file, say, 'F:/CBSE/
class11/ch5/welcome.py'. Once the file is opened, on IDLE's menu bar, follow the click sequence RUN-> Run
Module(F5), and the result of executing the Python script will be displayed in IDLE Shell, as shown in Fig 5.7.
120 Touchpad Computer Science (Ver. 2.0)-XI

