Python Execution Modes Class 11 CBSE Computer Science: Interactive Mode and Script Mode
Class 11 · Computer Science
Python Execution Modes (CBSE Class 11 Computer Science)
Python programs can be executed in different ways depending on the purpose. During learning and testing, programmers often execute individual statements immediately, whereas for larger applications, programs are written in files and executed later. Python provides two execution modes:
- Interactive Mode
- Script Mode
Learning Objectives
- Understand Python execution modes.
- Learn Interactive Mode.
- Learn Script Mode.
- Differentiate between Interactive Mode and Script Mode.
- Know when to use each execution mode.
What is Python Execution?
Execution means running a Python program so that the computer performs the instructions written by the programmer.
Write Program
│
▼
Execute Program
│
▼
Display Output
Python Execution Modes
Python
│
┌───────┴────────┐
▼ ▼
Interactive Mode Script Mode
Interactive Mode
Interactive Mode allows users to execute Python statements one at a time. As soon as a statement is entered, Python immediately executes it and displays the result.
The Python prompt (>>>>) indicates that Python is ready to accept commands.
Example
>>> print("Welcome")
Welcome
>>> 10 + 20
30
>>> name = "Sachin"
>>> print(name)
Sachin
Characteristics of Interactive Mode
- Executes one statement at a time.
- Displays output immediately.
- Useful for learning Python.
- Useful for testing small programs.
- Commands are not saved automatically.
Advantages of Interactive Mode
- Immediate execution.
- Easy debugging.
- Suitable for beginners.
- Helpful for testing expressions.
Disadvantages of Interactive Mode
- Programs are not saved automatically.
- Not suitable for large applications.
- Difficult to reuse long programs.
Script Mode
In Script Mode, Python programs are written in a file with the .py extension and saved on the computer. The saved file can be executed whenever required.
Creating a Python Script
- Open IDLE or any Python editor.
- Click File → New File.
- Write the Python program.
- Save the file with the extension .py.
- Select Run → Run Module or press F5.
Example Program
print("Welcome to Python")
print("CBSE Class 11")
print("Computer Science")
Output
Welcome to Python
CBSE Class 11
Computer Science
Characteristics of Script Mode
- Programs are stored in files.
- Entire program executes together.
- Suitable for large applications.
- Programs can be edited and reused.
- Easy to maintain.
Advantages of Script Mode
- Programs are permanently saved.
- Easy modification.
- Suitable for large projects.
- Easy to share with others.
Disadvantages of Script Mode
- Entire file must be executed.
- Requires saving before execution.
- Slightly slower for quick testing.
Interactive Mode vs Script Mode
| Interactive Mode | Script Mode |
|---|---|
| Statement-by-statement execution. | Entire program executes together. |
| Output appears immediately. | Output appears after execution. |
| Programs are not saved automatically. | Programs are saved in .py files. |
| Suitable for learning and testing. | Suitable for software development. |
| Difficult to reuse code. | Programs can be reused easily. |
Execution Process
Interactive Mode
Type Statement
│
▼
Immediate Execution
│
▼
Display Output
Script Mode
Write Program
│
▼
Save (.py)
│
▼
Run Program
│
▼
Display Output
Think Like a Programmer
Suppose you want to calculate:
25 × 45
The fastest method is Interactive Mode because you need only one statement.
Now suppose you want to create a Student Result Management Program consisting of 200 lines of code.
The correct choice is Script Mode because the program can be saved, edited, and executed multiple times.
Real-Life Example
- Interactive Mode is like using a calculator. You enter one calculation and get the result immediately.
- Script Mode is like writing a complete report in Microsoft Word, saving it, editing it later, and printing it whenever required.
Common Errors
- Forgetting to save the file before running.
- Saving the file without the .py extension.
- Confusing Interactive Mode with Script Mode.
- Trying to write large programs in Interactive Mode.
Exam Tips
- Remember that Interactive Mode executes one statement at a time.
- Script Mode executes the complete program.
- Script files use the .py extension.
- Interactive Mode is best for testing small code snippets.
- Script Mode is preferred for developing complete applications.
Frequently Asked Questions (FAQs)
1. What are the two execution modes of Python?
Interactive Mode and Script Mode.
2. Which mode is suitable for beginners?
Interactive Mode because it provides immediate feedback.
3. Which mode is used to develop large programs?
Script Mode.
4. Which file extension is used for Python programs?
.py
5. Can a Python script be modified after saving?
Yes. Script files can be edited and executed again whenever required.
Summary
- Python programs can be executed in Interactive Mode or Script Mode.
- Interactive Mode executes one statement at a time and provides immediate results.
- Script Mode executes an entire program stored in a .py file.
- Interactive Mode is suitable for learning and testing.
- Script Mode is suitable for developing complete applications.
- Understanding both execution modes helps programmers choose the appropriate method for different programming tasks.