Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Chapter5 Getting Started With Python

Uploaded by

Arpit Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Chapter5 Getting Started With Python

Uploaded by

Arpit Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

CHAPTER-5

PRESENTED BY NUMPY GROUP


Python is basically a high-level programming language. It is a
dynamic and free open-source language in nature. Moreover, it
uses an interpreter for converting the source code into machine
code. Furthermore, it supports both object-oriented programming
as well as procedure-oriented programming. It is such a language
that is highly readable and uses English keywords.
Guido Van Rossum developed Python in the February 1991. He
developed it at the National Research Institute for Mathematics
and Computer Science in the Netherlands.

Python is Generally-purpose interpreted, interactive, object-


oriented and high-level programming language.

It is derived from many languages like C, C++, Algol-68, ABC,


Unix shell, etc.
Guido van Rossum (born 31st January, 1956) is a Dutch
programmer. He is best known as the author of the Python
programming language, for which he is the "Benevolent Dictator
For Life" (BDFL), which means that he continues to oversee
Python development, making decisions when necessary. He
received a master's degree in Mathematics and Computer
Science from the University of Amsterdam in 1982. His brother
contributed in designing the typeface, used in the "Python
Powered" logo.
Python is a good programming language for
beginners .It I also very famous for :-
1)simple programming syntax
2)code readability
The user can write and execute the program in a
much simpler way as compared to the other
programming language .There are many features
of python :-
1)easy to learn :- Due to simple English and the easy syntax. This allows learners to
graph the language very quickly.

2)Interpreted language :- Code execution and code executed line by line

3)Interactive mode :- It is a command line she which gives immediate feedback for
each statement. While running previously fed statement in active memory

4)Case sensitive :- This means differentiating between the uppercase and


lowercase letters. The keywords are case sensitive . All the keywords are in
lowercase except (true , false , none ) . It also case sensitive when it deal with
identifiers . For ex :- Num and num are considered be two different identifiers
5) Free and open source :- It means you can freely distribute the copies of the software,
read the source code. Python is developed under making it freely usable And
distributable , even for commercial use . Python 's license is administrated by the python
software foundation.

6) Cross platform - language :- It is platform independence. It means if python code had


been developed in windows then it's library can also run on there platform. Viz.VINX ,
LINUX , Windows Macintosh , etc

7) Dynamic type - language :- In python , the user does not need to define the data type
of each of the variable used in the code as by default , the system defines the data type
.Fir ex :- If a user enter two variable A=25 , B =10Then , when the sum 'a' and 'b' is
calculated , it will result in 35 . Then , system has by default defined the data type as
integer .
8) Completeness :- Support wide range of library

9)GUI programming support :- Graphical user interface can be made using a module such
as py qt5 , py qt4 , wx python or thinker in python.
like the other programming languages, Python also has some limitations. Some of
them are mentioned below:

Performance and Speed:-


Python is slower in execution as compared to the other programming languages
like Java and C++. This happens since the execution of Python program takes place
with the help of an interpreter, instead of a compiler. As a result, the Python code
is executed line by line, which slows down the speed and performance.

Simplicity:-
Python is one of the simplest programming languages, which can indeed be a
problem. Its syntax is very simple and makes a programmer more of a Python
person. As a matter of fact, the users becomes so accustomed to its features that
they might feel it tougher to learn or work on other programming languages.
Weak In Mobile Computing:-
Python is a very simple programming language. The developers always need to write mobile apps
in a particular programming language according to the mobile platform. the developers prefer to
use Python directly for developing mobile apps because of its slow speed. Thus, it is very rarely
used for apps development.

Application Portability:-
installation of a specific version of Python interpreter on the operating system is needed to run
the application on that platform. Thus, the developers face problems in porting the application
from one platform to another.

Lacks Web Development Capabilities:-


Python does not come with strong built-in web development capabilities. It does not boost the
web applications' performance across multiple browsers. Python developers have to use a
number of Python web frameworks additionally to develop their web applications.For example:
Django, TurboGears, web2py, etc.
1. Game Development Like Java and C++, Python also has various modules
and libraries that provide support to develop video and 3D games. For
example, PySoy is a cross- platform 3D game engine which enables the
users to develop interactive games. Some popular games which have
been built using Python are Civilization-IV, Disney's ToonTown Online,
Vega Strike, etc.

2. 2. Web Development It is one of the most astonishing applications of


Python. This is because Python comes up with a wide range of
frameworks like Django, Flask, Bottle, and a lot more that provide ease to
developers. Furthermore, Python has inbuilt libraries and tools which
make the web development process completely effortless
3. Desktop GUI Python is an interactive programming language that
helps developers to create GUIs easily and efficiently. It has a huge list
of inbuilt tools like PyQT, kivy, wx Python, and many other libraries
like them to build a fully functional GUI in an extremely secure and
efficient manner.

4 Artificial Intelligence Artificial intelligence is one of the ever growing


branches of computer science, where one can learn and develop the
power of thinking and interacting with computers. Using Al, the
computer can be made to remember and learn based on past
experiences, and to draw inferences from it (through stored data).
Algorithms can also be made to make the computer learn by itself.
Pandas, Scikit-Learn. NumPy are a few examples of such applications
of artificial intelligence.
5. Audio and Video Applications Python is also a popular
programming language, used in developing audio and video
applications using Python libraries. The video and audio
applications such as TimPlayer and Cplay have been developed
on the said platform and they provide better stability and
performance as compared to other media players.

6. CAD Applications Computer Aided Designing is one of the


most complicated applications of computers which is used in
designing drafting or modelling parts, products or structures. It
is widely used by architects, engineers and artists to create
objects and their representation in 2D drawings and 3D
models. The most well-known application used for CAD is the
Fandango.
Computational thinking:- A problem solving approach
using concepts and ideas for computer science which also
involves expressing solution to those problems logically
which enable us to analyse using a computer and other
tools.

Decomposition:- it is the first stage in which big task or


Complex problems are broken down into smaller task
which help us to understand the entire process
Pattern Recognition:- it is the second stage in which we look
for similarities and differences within the problem so that we
can easily solve it

Abstraction:- In this we have to focus on the important


information given in the problem and avoiding all the
unuseful problem.

Algorithms:- The last and final final stage where step by step
instructions to be followed for finding the solution of the
problem
Decomposition For ex:- we have to find sum if all the numbers from 1
to 100 To make it easy we can do 1+2+3+4...................97+98+99+100

Pattern Recognition:- 1+100=1012+99=1013+97=101


And so

Abstraction:- Number of times 101 comes 100/2=50


(Sum of numbers)*(Number of times it comes) =101*50=5050

Algorithm:-Step-1 Start
Step-2 Sum the lowest and highest numbers
Step-3 find Number of terms and dividing the highest number by 2
Step-4 Multiply step 1 & step2
Step-5 Display the result
Step-6 Stop
What is Problem Solving?
Problem solving is the process of identifying a problem, analyze
the problem, developing an algorithm for the identified problem
and finally implementing the algorithm to develop program.

Steps for problem solving


There are 4 basic steps involved in problem solving
• Analyze the problem
• Developing an algorithm
• Coding
• Testing and debugging
Steps for problem solving
There are 4 basic steps involved in problem solving
• Analyze the problem
• Developing an algorithm
• Coding
• Testing and debugging

Analyze the problem


Analyzing the problem is basically understanding a problem
very clearly before finding its solution. Analyzing a problem
involves

• List the principal components of the problem


• List the core functionality of the problem
• Figure out inputs to be accepted and output to be produced
Developing an Algorithm:-
• A set of precise and sequential steps written to solve a problem
• The algorithm can be written in natural language
• There can be more than one algorithm for a problem among which we can select the
most suitable solution.

Testing and Debugging:-


After writing program it has to be tested on various parameters to ensure that program is
producing correct output within expected time and meeting the user requirement.

There are many standard software testing methods used in IT industry such as
• Component testing
• Integration testing
• System testing
• Acceptance testing
What is Algorithm?
• A set of precise, finite and sequential set of steps written to solve a problem
and get the desired output.
• Algorithm has definite beginning and definite end.
• It lead to desired result in finite amount of time of followed correctly.

Why do we need Algorithm?


• Algorithm helps programmer to visualize the instructions to be written clearly.
• Algorithm enhances the reliability, accuracy and efficiency of obtaining
solution.
Algorithm is the easiest way to describe problem without going into too much
details.
• Algorithm lets programmer understand flow of problem concisely.
Characteristics of a good algorithm
• Precision - the steps are precisely stated or defined.
• Uniqueness-results of each step are uniquely defined and only depend on the
input and the result of the preceding steps.
• Finiteness - the algorithm always stops after a finite number of steps.
• Input - the algorithm receives some input.
• Output - the algorithm produces some output.

What are the points that should be clearly identified while writing Algorithm?
• The input to be taken from the user
• Processing or computation to be performed to get the desired result
• The output desired by the user
Representation of Algorithm
An algorithm can be represented in two ways:
• Flow chart
• Pseudo code

Flow chart
• Flow chart is visual representation of an algorithm.
• It's a diagram made up of boxes, diamonds and other shapes, connected by arrows.
• Each step represents a step of solution process.
• Arrows in the follow chart represents the flow and link among the steps.
Flow Chart Examples
Example 1: Write an algorithm to divide a number by
another and display the quotient.

Input: Two Numbers to be divided


Process: Divide number1 by number2 to get the
quotient
Output: Quotient of division

Algorithm
Step 1: Input a two numbers and store them in num1
and num2 Step 2: Compute num1/num2 and store its
quotient in num3

Step 3: Print num3


Pseudo code
• Pseudo code means 'not real code'.
• A pseudo code is another way to represent an algorithm. It is an informal
language used by programmer to write algorithms.
• It does not require strict syntax and technological support.
• It is a detailed description of what algorithm would do.
• It is intended for human reading and cannot be executed directly by computer.
• There is no specific standard for writing a pseudo code exists.

Keywords used in writing pseudo code


• INPUT
• COMPUTE
• PRINT
• INCREMENT
• DECREMENT
• IF/ELSE
• WHILE
• TRUE/FALSE
Example: write an algorithm to display the square of a given number.
Input, Process and Output Identification
Input: Number whose square is required
Process: Multiply the number by itself to get its square
Output: Square of the number

Algorithm
Step 1: Input a number and store it to num.
Step 2: Compute num * num and store it in square.
Step 3: Print square.

Pseudo code
INPUT num
COMPUTE square = num*num
PRINT square
Flow of Control
An algorithm is considered as finite set of steps that are executed in a sequence. But
sometimes the algorithm may require executing some steps conditionally or
repeatedly. In such situations algorithm can be written using
• Sequence
• Selection
• Repetition

Selection
Selection in algorithm refers to Conditionals which means performing operations
(sequence of steps) depending on True or False value of given conditions. Conditionals
are written in the algorithm as follows:
If <condition> then
Steps to be taken when condition is true
Otherwise
Steps to be taken when condition is false
Algorithm, Pseudocode, Flowchart with Selection (Using if)
Examples
Example: write an algorithm, pseudocode and flowchart to
display larger between two numbers
Input, Process and Output Identification
INPUT: Two numbers to be compared
PROCESS: compare two numbers and depending upon True and False value of
comparison display result
OUTPUT: display larger no

Algorithm
STEP1: read two numbers in num1, num2
STEP 2: if num1 > num2 then
STEP 3: display num1
STEP 4: else
STEP 5: display num2
Pseudo code
INPUT num1, num2
IF num1 > num2 THEN
PRINT "num1 is largest"
ELSE
PRINT "num2 is largest"
ENDIF

Flow Chart:-
Repetition
• Repetition in algorithm refers to performing
operations (Set of steps) repeatedly for a given
number of times (till the given condition is true).
Repetition is also known as Iteration or Loop
Repetitions are written in algorithm is as
follows:

While <condition>, repeat step numbers


Steps to be taken when condition is true
End while
Algorithm, Pseudocode, Flowchart with Repetition (Loop) Examples
Example: write an algorithm, pseudocode and flow chart to display "Techtipnow" 10 times
Algorithm
Step1: Set count = 0
Step2: while count is less than 10, repeat step 3,4
Step 3:
print "techtipnow"
Step 4:
count = count + 1
Step 5: End while

Pseudocode
SET count = 0
WHILE count<10
PRINT "Techtipnow"
Count = count + 1
END WHILE
FLOWCHART:-
Decomposition
• Decomposition means breaking down a complex problem into smaller sub problems to solve them
conveniently and easily.
• Breaking down complex problem into sub problem also means analyzing each sub problem in detail.
• Decomposition also helps in reducing time and effort as different subprograms can be assigned to
different experts in solving such problems.
• To get the complete solution, it is necessary to integrate the solution of all the sub problems once
done.

Following image depicts the decomposition of a problem


Working in Python
Python allows the user to perform the tasks in two different modes.
The Two Ways are :-
1. Interactive Mode
2. Script Mode
Interactive Mode:-
Interactive mode refers to the mode where the user is able to instantly
see the output, for the input given.
The moment when a command is typed in front of the Command
Prompt (>>>) and the 'Enter Key' is pressed, the output will appear
instantly on the next line of the Interactive screen.

How to Work in Interactive Mode?

Step 1Click IDLE (Python 3.8 32-bit) icon which is available on the Start
pop up screen.
OR
On the desktop
OR
If pinned to the taskbar.

It will open the Interactive window Python Shell.


When the Screen will be Opened
1. Python version 3.8.1
2. Date of it's release
3. Time of it's release will appear on the screen
Step 2 Type a command or statement in front of the
Python command Prompt.
Step 3 Press 'Enter' Key.
Python will immediately give you the result.

Why Interactive Mode?


1.Because Interactive Mode makes it easy to experiment
with different features of Language development.

2. Interactive mode becomes useful where single line


commands/statements are used.
Note:-
The Output of the command will be available on the
next line of the same screen and without Python
Command prompt.
them.
Advantages & Uses of Interactive mode:-
1. For Arithmetical operations.
2. For Trying out small snippets of code.
3. For Testing things out, as you're writing.

Script Mode
Script mode refers to the mode where the user is
able to execute multiple commands or statements
simultaneously.
How to work in Script mode
Step 1Click IDLE(Python version 3.8 32-bit) icon
which is available on the Start pop up screen.
OR
On the Desktop
OR
If pinned to the Taskbar
Step 2
1. Click 'File’
2. Select New 'File’ An Untitled Window will appear.
This window provides the user a Platform to write
programs on it
Step 3
Type a Code in the 'Untitled' window to program file.
Step 4
1. Click 'File’.
2. Select 'Save As’.
Step 5
Select the File, where you want to save the Program File
on you Computer.
Step 6
Enter the File name (say Num) in the 'File name' text box.
Step 7
Click on 'Save' button.
The File will be saved in the system with the extension .py
(by default).
Why Script Mode?

1.Because it allows the user to execute multiple statements/commands.


2. In Script mode the user can save complete instructions to make a program file.

Note:-
When you run a program, the output will be available on the Interactive window.

Advantage of Script mode


As no Longer Our Python Script get Lost we can Make Changes whenever required.

Execution of the Program File


1. Open File from the Saved location.
2. Click 'Run’.
3. Click 'Run Module’.
The Program is Executed and the Output of the Program file will be available on the Interactive
window.
Opening a Pre-existing Program file
Step 1Click Python shell icon.
Step 2
1. Click on 'File' Menu.
2. Select 'Open’.
Step 3
Select the Drive where the program file is saved
(desktop).
Step 4
Select your file (say Num) and it will be available in
the 'File Name’.
Step 5
Click on 'Open' button. Your File is Open
Step 6
You can edit(if needed) or execute the program.

You might also like