Page 284 - AI Ver 1.0 Class 9
P. 284
Working in Python
We can interact with Python in two different modes:
• Interactive Mode (Python IDLE-Shell Mode): In this mode, you type one command at a time in front of the
Python command prompt (>>>) and Python gives you the result based on the command given. It means you
run code directly on shell mode accessed through the terminal of an operating system. This mode will not save
your commands and outputs and should be used only when you want to play with small one-line instructions.
You can also use the print( ) function to print the messages on the Shell window. For example,
Interactive mode
• Script Mode (Editor): In this mode, you save all your commands together in any text editor with the extension
.py. When we run this text file.py then the output of the commands will be displayed in Shell mode. The steps
to create and run script file in script mode are:
Step 1 Click on the File New File option in Shell mode. A new blank text editor
appears.
Step 2 Type the commands and then click on the File Save as option to save the file.
The Save As dialog box appears.
Step 3 Select the desired location to save the file and type the file name in the File
name box. In this case, we have typed the file name as MyFirstFile.py.
New File option
Script mode
Step 4 Click on the Run Run Module or press F5 key to run the program. The program will execute and
the output will be shown in the Shell window.
Running a script
282 Touchpad Artificial Intelligence-IX

