Breaking

Python Basic Questions

 

Machine Language



A computer is an electronic machine that can recognize/follow instruction written in binary form, i.e. using only 0s and 1s. Computer’s natural language is machine language, which can directly understand by it. This language is not portable and it is machine dependent. A program written in 1s and 0s is called Machine language.  For a specific operation binary code is used in machine language. A set of Instructions in binary pattern is associated with each computer. It is difficult to communicate with a computer in terms of 1s and 0s.

 

Assembly Language

In assembly language binary bits are used and it is a machine language. The programmer can use English like words as commands that can be easily interpreted by the programmer. The computer manufacturers started providing English like words abbreviated as mnemonics. The program contains alphanumeric symbols instead of 1s and 0s.

In assembly language, machine operations are represented by mnemonic codes (such as ADD, MUL, etc.) and symbolic names that specify the memory address. Each instruction of an assembly language contains operation code byte and operand byte/s. 

 

Consider the following example 

 

                        Example        

MOV X, 10 

                        MOV Y, 20       

ADD X, Y 

 

Here the mnemonic MOV indicates an operation to store the value of variable X as 10. The mnemonic ADD implies addition of the contents of variables X, Y and finally storing the result in variable X itself.  

High-level Language  

 

In High level language instructions are written just like English language words. Here ‘high’ does not imply that the language is complicated. It means that the language is more problem solving oriented. Generally, high-level languages are platform independent. 

For example, a statement to calculate the square of a number can be written in a high-level language as 

 

Square = number * number

The compilers employed to translate high-level language program to machine language.

 

2.  What is a compiler? 

 

It is software that translates a program written in a high-level language into machine language.

 

3.  What is an interpreter?

 

While a compiler converts the whole source code into an equivalent object code or machine code, the interpreter reads the source code line by line and converts it into object code (i.e. a code understandable to the machine).

 

4.  Differentiate between a compiler and an interpreter. 

The interpreter reads the source code line by line and converts it into object code. Whereas a compiler is a software that translates complete program written in a high-level language into machine language.  

 

5.  What is a linker? 

It is a program that links different program modules and libraries to form a single executable program. It can consist of hundreds of lines of code. Before the execution of a program, all the modules of the program and the required libraries are linked together using a software called a linker.

 

 

6.  What is a loader?

It is used to load and relocate an executable program in the main memory during execution.

 

7.  Explain the internal working of Python in brief. 

 

The Python interpreter performs the following steps to execute a

Python program or run a set of instructions in interactive mode  

STEP 1: The interpreter reads a Python code or instruction. Then it verifies that the instruction is well formatted, i.e. it checks the syntax of each line. If it encounters any error, it immediately halts the translation and shows an error message.  

STEP 2: If there is no error, i.e. if the Python instruction or code is well formatted then the interpreter translates it into its equivalent form in low level language called “Byte Code”. Thus, after successful execution of Python script or code, it is completely translated into byte code. 

 

STEP 3: Byte code is sent to the Python Virtual Machine (PVM). Here again the byte code is executed on PVM. If an error occurs during this execution then the execution is halted with an error message. 

 

 

8. Describe the memory unit of a computer system in brief.

 

Internal memory: It refers to the set of registers confined within the CPU. These registers hold temporary data/results when a computation is in progress. 

 

Primary memory: It is a storage area in which all the programs are fetched from secondary memory and executed   

Secondary memory: It is known as external memory or storage memory. Programs and data are stored here for the long term. Hard disk, floppy disk, CDs, DVDs and magnetic tapes are different forms of secondary memory.

No comments: