Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
84 views14 pages

Unit 1.1

Uploaded by

smita6241
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views14 pages

Unit 1.1

Uploaded by

smita6241
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Unit 1.

Introduction to Python
 Introduction to Programming Concepts

Problem
• A problem is any situation in which you have a starting point, a set of directions and the
need to create a solution or answer.
• Problem is an issue or obstacle which makes it difficult to achieve a desired goal,
objective or purpose

Definition
Problem Solving is “the process of working through details of a problem to reach a
solution”.

Framework for problem solving:


STEP1: Understanding the problem
STEP2: Devising a Plan/Making a plan of solution
STEP3: Carrying out the plan
STEP4: Looking back/Verifying

1. TRIAL AND ERROR TECHNIQUE//METHOD :


Some complex problems can be solved by a technique that is called trial and
error. Trial and error is typically good for problems where you have multiple chances
to get the correct solution.

For example: while trial and error may be excellent in finding solutions to
mechanical or engineering problems.

2. BRAIN STORMING TECHNIQUES :


“Brainstorming is a group method for obtaining new ideas and business
solutions. The groups are organized for sitting together and stimulate greater
creativity by exchange of mutual experiences and participating in the discussions.”

For example: It is commonly used for advertising, the development of new products,
process management and business planning.
3. DIVIDE AND CONQUER TECHNIQUES :
In the technique, the main problem is divided into several smaller sub problems
and then it is solved recursively. At last combine these solutions to create the
solution of the original problem.

 Algorithm
• A algorithm is a procedure or formula for solving a problem. It can defined as a
step-by-step procedure to solve a particular problem or program.
• An algorithm is a sequence of finite instructions used for calculations and data
processing.

 Algorithm for Addition of two Integers


Step 1: Start.
Step 2: Read numbers num1 and num2
Step 3: sum=num1+num2
Step 4: Display sum
Step 5: Stop.

 Flowchart
• Flow chart is diagrammatic representation of an algorithm. It is built using
• different types of boxes of symbols. The operation to be performed is
• written in the box. All symbols are interconnected by arrows to indicate the
• flow of information and processing.

Following are the standard symbols used in drawing flowcharts.


 Program
A computer program is a sequence of instructions written using a Computer
Programming Language to perform a specified task by the computer.

• The two important terms that we have used in the above definition are −

 Sequence of instructions
 Computer Programming Language

 A computer program is also called a computer software, which can range from two
lines to millions of lines of instructions.
 Computer program instructions are also called program source code and computer
programming is also called program coding.
 A computer without a computer program is just a dump box; it is programs that make
computers active.

Python
 Python is a simple, general purpose, high level, and object-oriented programming
language.
 Python is an interpreted scripting language also. Guido Van Rossum is known as the
founder of Python programming.
 On December 3, 2008, Python 3.0 (also called "Py3K") was released.

 Python Features
 Easy to Learn and Use
Python is easy to learn as compared to other programming languages. Its syntax is
straightforward and much the same as the English language. There is no use of the
semicolon or curly-bracket, the indentation defines the code block. It is the
recommended programming language for beginners.
 Expressive Language
Python can perform complex tasks using a few lines of code. A simple example, the
hello world program you simply type print("Hello World"). It will take only one line to
execute, while Java or C takes multiple lines.
 Interpreted Language
Python is an interpreted language; it means the Python program is executed one line at
a time. The advantage of being interpreted language, it makes debugging easy and
portable.
 Cross-platform Language
Python can run equally on different platforms such as Windows, Linux, UNIX, and
Macintosh, etc. So, we can say that Python is a portable language. It enables
programmers to develop the software for several competing platforms by writing a
program only once.
 Free and Open Source
Python is freely available for everyone. It is freely available on its official
website www.python.org
 Object-Oriented Language
Python supports object-oriented language and concepts of classes and objects come
into existence. It supports inheritance, polymorphism, and encapsulation, etc. The
object-oriented procedure helps to programmer to write reusable code and develop
applications in less code.
 Extensible
It implies that other languages such as C/C++ can be used to compile the code and
thus it can be used further in our Python code. It converts the program into byte code,
and any platform can use that byte code.
 Large Standard Library
It provides a vast range of libraries for the various fields such as machine learning, web
developer, and also for the scripting. There are various machine learning libraries, such
as Tensor flow, Pandas, Numpy, Keras, and Pytorch, etc. Django, flask, pyramids are
the popular framework for Python web development.
 GUI Programming Support
Graphical User Interface is used for the developing Desktop application. PyQT5,
Tkinter, Kivy are the libraries which are used for developing the web application.
 Integrated
It can be easily integrated with languages like C, C++, and JAVA, etc. Python runs code
line by line like C,C++ Java. It makes easy to debug the code.
 Embeddable
The code of the other programming language can use in the Python source code. We
can use Python source code in another programming language as well. It can embed
other language into our code.
 Dynamic Memory Allocation
In Python, we don't need to specify the data-type of the variable. When we assign some
value to the variable, it automatically allocates the memory to the variable at run time.
Suppose we are assigned integer value 15 to x, then we don't need to write int x =
15. Just write x = 15.
 Python Applications

1) Web Applications

We can use Python to develop web applications. It provides libraries to handle


internet protocols such as HTML and XML, JSON, Email processing, request,
beautifulSoup, Feedparser, etc.

One of Python web-framework named Django is used on Instagram.

2) Desktop GUI Applications


The GUI stands for the Graphical User Interface, which provides a smooth
interaction to any application. Python provides a Tk GUI library to develop a user
interface.
3) Console-based Application
Console-based applications run from the command-line or shell. These applications
are computer program which are used commands to execute.
4) Software Development
Python is useful for the software development process. It works as a support
language and can be used to build control and management, testing, etc.
5) Scientific and Numeric
 This is the era of Artificial intelligence where the machine can perform the
task the same as the human. Python language is the most suitable language
for Artificial intelligence or machine learning.
 It consists of many scientific and mathematical libraries, which makes easy to
solve complex calculations.
 Implementing machine learning algorithms require complex mathematical
calculation.
 Few popular frameworks of machine libraries are given below.
 SciPy , Scikit-learn, NumPy , Pandas, Matplotlib
6) Business Applications
 Business Applications differ from standard applications.
 E-commerce and ERP are an example of a business application.
 Oddo is an example of the all-in-one Python-based application which offers a
range of business applications.
 Python provides a Tryton platform which is used to develop the business
application.

7) Audio or Video-based Applications


 Python is flexible to perform multiple tasks and can be used to create
multimedia applications.
 Some multimedia applications which are made by using Python
are TimPlayer, cplay, etc.
8) 3D CAD Applications
 The CAD (Computer-aided design) is used to design engineering related
architecture.
 It is used to develop the 3D representation of a part of a system.
 Python can create a 3D CAD application by using the following functionalities.
 Fandango (Popular )
CAMVOX, HeeksCNC , AnyCAD , RCAM

9) Enterprise Applications
Python can be used to create applications that can be used within an Enterprise or
an Organization. Some real-time applications are OpenERP, Tryton, Picalo, etc.
10) Image Processing Application
Python contains many libraries that are used to work with the image. The image can
be manipulated according to our requirements.
First Python Program
In this Section, we will discuss the basic syntax of Python, we will run a simple program to
print Hello World on the console.

Python provides us the two ways to run a program:

o Using Interactive interpreter prompt


o Using a script file

Interactive interpreter prompt.


To open the interactive mode, open the terminal (or command prompt) and type python
(python3 in case if you have Python2 and Python3 both installed on your system).

It will open the following prompt where we can execute the Python statement and check their
impact on the console.

After writing the print statement, press the Enter key.


Here, we get the message "Hello World !" printed on the console.

Using a script file (Script Mode Programming)


The interpreter prompt is best to run the single-line statements of the code. However, we cannot
write the code every-time on the terminal. It is not suitable to write multiple lines of code.

Using the script mode, we can write multiple lines code into a file which can be executed later.
For this purpose, we need to open an editor like notepad, create a file named and save it
with .py extension, which stands for "Python".

print ("hello world"); #here, we have used print() function to print the message on the console.

To run this file named as first.py, we need to run the following command on the terminal.

Step - 1: Open the Python interactive shell, and click "File" then choose "New", it will open a
new blank script in which we can write our code.
Step -2: Now, write the code and press "Ctrl+S" to save the file.

Step - 3: After saving the code, we can run it by clicking "Run" or "Run Module". It will display
the output to the shell.
The output will be shown as follows.

Multi-line Statements
Multi-line statements are written into the notepad like an editor and saved it with .py extension.
In the following example, we have defined the execution of the multiple code lines using the
Python script.

Code:
name = "Andrew Venis"
branch = "Computer Science"
age = "25"
print("My name is: ", name, )
print("My age is: ", age)

Script File:
Basic Syntax of Python

Python Comments
• Comments can be used to explain Python code.
• Comments can be used to make the code more readable.
• Comments can be used to prevent execution when testing code.

Creating a Comment
Comments starts with a #, and Python will ignore them:

Example
#This is a comment
print("Hello, World!")

Comments can be placed at the end of a line, and Python will ignore the rest of the line:

Example
print("Hello, World!") #This is a comment

A comment does not have to be text that explains the code, it can also be used to prevent
Python from executing code:

Example
#print("Hello, World!")
print("Cheers, Mate!")

Multi Line Comments


Python does not really have a syntax for multi line comments.

To add a multiline comment you could insert a # for each line:

Example
#This is a comment
#written in
#more than just one line
print("Hello, World!")

Or, not quite as intended, you can use a multiline string.


Since Python will ignore string literals that are not assigned to a variable, you can add a
multiline string (triple quotes) in your code, and place your comment inside it:

Example
"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")

As long as the string is not assigned to a variable, Python will read the code, but then ignore
it, and you have made a multiline comment.

You might also like