Review of Python & Concept of Oops - 12th CBSE

Computer Science Class–XII - CBSE
Unit-1: Review of Python & Concept of Oops

We have learnt Python programming language in the 11th class and continue to learn the same language program in class 12th also. We also know that Python is a high level language and we need to have Python interpreter installed in our computer to write and run Python program. Python is also considered as an interpreted language because Python programs are executed by an interpreter. We also learn that Python shell can be used in two ways, viz., interactive mode and script mode. Interactive Mode: Interactive Mode, as the name suggests, allows us to interact with OS. Hear, when we type Python statement, interpreter displays the result(s) immediately. That means, when we type Python expression / statement / command after the prompt (>>>), the Python immediately responses with the output of it. Let's see what will happen when we type print "WELCOME TO PYTHON PROGRAMMING" after the prompt


>>>print "WELCOME TO PYTHON PROGRAMMING"

WELCOME TO PYTHON PROGRAMMING

Example:
>>> print 5+10
15
 >>> x=10

>>> y=20

>>> print x*y 200

Script Mode: In script mode, we type Python program in a file and then use interpreter to execute the content of the file. Working in interactive mode is convenient for beginners and for testing small pieces of code, as one can test them immediately. But for coding of more than few lines, we should always save our code so that it can be modified and reused. Python, in interactive mode, is good enough to learn, experiment or explore, but its only drawback is that we cannot save the statements and have to retype all the statements once again to re-run them.

Example: Input any two numbers and to find Quotient and Remainder.
Code: (Script mode)
a = input ("Enter first number")
b = input ("Enter second number")
print "Quotient", a/b
print "Remainder", a%b
Output: (Interactive Mode)
Enter first number10
Enter second number3
Quotient 3
Remainder 1 

No comments:

Post a Comment