Problem Solving and Python Programming: UNIT II: Data Types, Expressions, Statements

Interactive and Script Modes

Python Programming

• Python has two basic modes : Interactive and Script

Interactive and Script Modes

AU : Dec.-19, Marks 8

• Python has two basic modes : Interactive and Script.

 

1) Interactive mode

Interactive mode is a command line shell which gives immediate feedback for each statement, while running previously fed statements in active memory. As new lines are fed into the interpreter, the fed program is evaluated both in part and in whole.

• The >>> is Python's way of telling you that you are in interactive mode. In interactive mode what you type is immediately run. For example - If we type 1+1 on the interpreter the immediate result i.e. 2 will be displayed by interpreter.


 

2) Script mode

• This is also called as normal mode. This is a mode in which the Python commands are stored in a file and the file is saved using the extension. py

• For example : We can write a simple Python program in script mode using following steps

Step 1: Open Python Shell by clicking the Python IDE.

Step 2: On File Menu Click on New File option.


Step 3: Give some suitable file name with extension .py (I have created test.py).

Step 4 : A file will get opened and the type some programming code. Sample file is as follows 

Step 5 : Now run your code by cliking onRun -> Run Module on Menu bar. Following screenshot illustrates it


For running the script we can also use F5 key.

Step 6 : The output will be displayed on the phython shell. It is as follows-


Review Question

1. Sketch the structures of interpreter and compiler. Detail the differences between them. Explain how python works in interactive mode and script mode with examples.

AU : Dec.-19. Marks (2+2+4)

 

Problem Solving and Python Programming: UNIT II: Data Types, Expressions, Statements : Tag: Engineering Python : Python Programming - Interactive and Script Modes