Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PYTHON

Compiler: a software that converts instructions/program into an understandable form so that


they can be read and executed by a computer. IDLE is the compiler that we will be using to
execute python programs.

Interactive Mode: In the interactive mode as we enter a command and press enter, the very
next step we get the output. The output of the code in the interactive mode is influenced by the
last command we give. Interactive mode is very convenient for writing very short lines of code.

Basically, we can write the program directly on the result screen itself without going through the
hassle of saving a different file. However, this functionality is not suitable for writing large
programs. Examples of Interactive mode:

In the above figure, the variables a and b are declared and printed on the shell screen itself.

Two variables are declared with values 15 and 21, then a variable ‘sum’ is declared which
performs the addition of those two. At last, the sum is printed.

Disadvantages of interactive mode: The interactive mode doesn’t save the statements. Once
we make a program for that time itself, we cannot use it in the future. In order to use it in the
future, we need to retype all the statements. Editing the code written in interactive mode is a
tedious task.
Script Mode: In the script mode, a python program can be written in a separate file. This file
can then be saved and executed by clicking the ‘Run’ button. We can view the code at any time
by opening the file and editing becomes quite easy. Script mode is very suitable for writing long
pieces of code. It is much preferred over interactive mode by developers. The file made in the
script mode is saved by default in the Python installation folder. While saving the file, it is
extremely necessary to save it with the ‘.py’ extension. Failing to do so, the code will not
run.

Once we press the Run button, the shell window(result screen) will pop up and display our
result. Examples of script mode:

Save the file with the .py extension as shown above, then click on Run to execute the program
and view your result.
Escape Sequences: They allow you to include special characters in strings. To do this, simply
add a backslash (\) before the character you want to escape. Different types of escape
sequences are:

➢ \n : It is called the newline sequence and is used to move to the next line on the result
screen. Example:

print(“Hello Everyone \n Good Morning”)

The result will print ‘Good Morning’ on the next line.

➢ \t : It is called the tab sequence. When we use it as a separator among the values, it
creates space between them. Example:

By using ‘\t’ the values of a, b and c are printed with spaces between them.

Important Programs:

Product of three numbers:


Program to convert miles into kilometers:

1 kilometer equals 1.6 times a mile. Hence, using this formula the computation is done. First, the
value of miles is taken from the user by using the input() function. Then Python calculates the
kilometer with the help of the formula provided by us.

Program to find the area and circumference of a circle:

The value of radius is provided by the user inside the program. Then the formulas for area and
circumference are written. Finally, these values are printed.
Program to convert Fahrenheit into Celcius:

Program to find the area and perimeter of a rectangle:

Keywords : Keywords in Python are reserved words that can not be used as a variable name,
function name, or any other identifier. Examples of keywords: If, else, for, do, while, from, etc

You might also like