Introduction To Python
Introduction To Python
Introduction To Python
problems.
You can think of programming as a collaboration between humans and computers, in which humans create
instructions for a computer to follow (code) in a language computers can understand.
Algorithm
Developing algorithm to solve particular problem In mathematics and computer science, an algorithm is a step-by-step
procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning.Algorithms
resemble recipes. Recipes tell you how to accomplish a task by performing a number of steps.
oven; mix flour, sugar, and eggs thoroughly; pour into a baking pan; and so forth.
• To introduce and appreciate approaches for defining and solving very complex tasks in terms of simpler
tasks;
Output: None
Steps:
6. Talk to friend
7. Hang up phone
Steps:
1. Take numbers a, b, c.
3. C=a+b
4. Print c*c
Steps:
1. Take numbers l, b, c, d.
3. c=l*b
4. d=2*c
5. Print d
Conditions in Algorithm
Algorithm: To check whether a person can vote or not
Input: A number age.
Output: Yes or No
Steps:
Else
Goto step 5
Algorithm: To give a bonus of Rs 1000 to those employees whose salary is more than Rs 5000
Input: Salary.
Steps:
Else
Goto step 5
4. total=salary+1000
5. total=salary+0
6. Print total
FLOW CHART
A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds,
and their order by connecting them with arrows. This diagrammatic representation illustrates a solution to a given
problem.
Computer Languages
The user of a computer must be able to communicate with it. That means, he must be able to give the
computer commands and understand the output that the computer generates. This is possible due to the invention of
computer languages.
Basically, there are two main categories of computer languages, namely Low Level Language and High Level
Language. Let us take a brief look at both these types of computer languages.
The main function of low level languages is to interact with the hardware of the computer. They help in
operating, syncing and managing all the hardware and system components of the computer. They handle all the
instructions which form the architecture of the hardware systems.
Machine Language
This is one of the most basic low level languages. The language was first developed to interact
with the first generation computers. It is written in binary code or machine code, which means it
basically comprises of only two digits – 1 and 0.
Assembly Language
This is the second generation programming language. It is a development on the machine
language, where instead of using only numbers, we use English words, names, and symbols. It is the
most basic computer language necessary for any processor.
The important feature about such high level languages is that they allow the programmer to write programs for all
types of computers and systems. Every instruction in high level language is converted to machine language for the
computer to comprehend.
Scripting Languages
Scripting languages or scripts are essentially programming languages. These languages employ a high level
construct which allows it to interpret and execute one command at a time.
Scripting languages are easier to learn and execute than compiled languages. Some examples are AppleScript,
JavaScript, Pearl etc.
Object-Oriented Languages
These are high level languages that focus on the ‘objects’ rather than the ‘actions’. To accomplish this, the
focus will be on data than logic.
The reasoning behind is that the programmers really cares about the object they wish to manipulate rather
than the logic needed to manipulate them. Some examples include Java, C+, C++, Python, Swift etc.
It has a systematic order functions and commands to complete a task or a program. FORTRAN, ALGOL, BASIC,
COBOL are some examples
Types of Language Translators
There are mainly three types of translators that are used to translate different programming languages into machine-
equivalent code:
1. Assembler
2. Compiler
3. Interpreter
Assembler
An assembler translates assembly language into machine code.
Assembly language consists of mnemonics for machine op-codes, so assemblers perform a 1:1 translation from
mnemonic to direct instruction. For example, LDA #4 converts to 0001001000100100.
Conversely, one instruction in a high-level language will translate to one or more instructions at the machine level.
Assembly code is often very efficient (and therefore fast) because it is a low-level language.
Assembly code is fairly easy to understand due to the use of English, like in mnemonics.
Assembly tends to be optimized for the hardware it is designed for, meaning it is often incompatible with different
hardware.
Lots of assembly code is needed to do a relatively simple task, and complex programs require lots of programming
time.
Compiler
A compiler is a computer program that translates code written in a high-level language into a low-level language,
machine code.
The most common reason for translating source code is to create an executable program (converting from high-level
language into machine language).
Source code is not included; therefore, compiled code is more secure than interpreted code.
Because the program generates an executable file, it can be run without the need for the source code.
Before a final executable file can be created, object code must be generated; this can be a time-consuming process.
The source code must be 100% correct for the executable file to be produced.
Interpreter
An interpreter program executes other programs directly, running through the program code and executing it line-by-
line. As it analyses every line, an interpreter is slower than running compiled code, but it can take less time to interpret
program code than to compile and then run it. This is very useful when prototyping and testing code.
Interpreters are written for multiple platforms; this means code written once can be immediately run on different
systems without having to recompile for each. Examples of this include flash-based web programs that will run on your
PC, Mac, gaming console, and mobile phone.
It is easier to create multi-platform code, as each different platform would have an interpreter to run the same code.
And here is the list of some of the main disadvantages of using an interpreter:
Source code is required for the program to be executed, and this source code can be read, making it insecure.
Due to the on-line translation method, interpreters are generally slower than compiled programs.