Experiment-1 123008
Experiment-1 123008
Objective: Getting started with Python and IDLE in interactive and batch modes.
Explanation: To write and run (execute) a Python program, we need to have a Python interpreter
installed on our computer or we can use any online Python interpreter. The interpreter is also called
Python shell. A sample screen of Python interpreter is shown in Figure 1:
Working in the interactive mode is convenient for testing a single line code for instant execution.
But in the interactive mode, we cannot save the statements for future use and we have to retype
the statements to run them again.
Script Mode
In the script mode, we can write a Python program in a file, save it and then use the interpreter to
execute it. Python scripts are saved as files where file name has extension “.py”. By default, the
Python scripts are saved in the Python installation folder. To execute a script, we can either:
1. Type the file name along with the path at the prompt. For example, if the name of the file
is prog1.py, we type prog1.py. We can otherwise open the program directly from IDLE as
shown in Figure 3.
2. While working in the script mode, after saving the file, click [Run]->[Run Module] from
the menu as shown in Figure 4.
3. The output appears on shell as shown in Figure 5.