0% found this document useful (0 votes)
3 views17 pages

Unit - 1 Python

This document provides an introduction to computing and Python programming, covering the basics of computing, types of computing devices, and the importance of algorithms and pseudocode. It explains the computing cycle, the identification of computational problems, and the significance of flowcharts in problem-solving. Additionally, it discusses the characteristics of algorithms and different approaches to designing them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

Unit - 1 Python

This document provides an introduction to computing and Python programming, covering the basics of computing, types of computing devices, and the importance of algorithms and pseudocode. It explains the computing cycle, the identification of computational problems, and the significance of flowcharts in problem-solving. Additionally, it discusses the characteristics of algorithms and different approaches to designing them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Unit-1

Module I: Introduction to Computing and Python Programming


Introduction to Computing and Problem Solving:
Computing is the process of using computers and computational techniques to solve
problems by creating software, algorithms and procedures to process data, store information,
and perform tasks efficiently.
Computing is the science and practice of using computers to process information and solve
problems. It forms the foundation of modern technologies such as software applications, data
analytics, cloud computing, and artificial intelligence.
Computing involves:
 Receiving data (input)
 Processing data according to instructions
 Storing data for future use
 Producing useful information (output)
It includes both the hardware (physical components) and software (programs and
applications) that work together to perform tasks.
Areas of Computing
1. Computer Science – Study of algorithms, programming, and software development.
2. Information Technology (IT) – Management and use of computer systems and
networks.
3. Data Science – Analysis and interpretation of data.
4. Artificial Intelligence (AI) – Development of intelligent systems that can learn and
make decisions.
5. Cybersecurity – Protection of computer systems and data.
Examples of Computing
 Searching for information on the internet
 Sending emails
 Using mobile applications
 Online banking transactions
 Data analysis and visualisation
 Artificial Intelligence applications such as chatbots
Importance of Computing
 Solves complex problems quickly
 Improves productivity and efficiency
 Enables communication and collaboration
 Supports scientific research and innovation
 Facilitates automation of tasks
Computing Cycle
Input

Processing

Storage

Output

Computing Devices:
A computing device is any machine capable of performing computing operations such as
input, processing, storage, and output. Computing devices are electronic systems that process
information and perform tasks. They range from smartphones and laptops to powerful
servers and supercomputers, playing a vital role in modern life.
Types of Computing Devices
1. Desktop Computer
 A personal computer designed for use at a desk.
 Used in homes, offices, and educational institutions.
 Example: Windows PC, iMac.
2. Laptop
 A portable computer with a built-in screen, keyboard, and battery.
 Can be carried and used anywhere.
 Example: Dell Inspiron, HP Pavilion.
3. Tablet
 A touchscreen computing device.
 Smaller and lighter than laptops.
 Example: Apple iPad, Samsung Galaxy Tab.
4. Smartphone
 A mobile device that combines communication and computing capabilities.
 Supports apps, internet access, and multimedia.
 Example: Android phones, iPhone.
5. Server
 A powerful computer that provides services and resources to other computers over
a network.
 Used in businesses, websites, and cloud computing.
6. Supercomputer
 The fastest and most powerful type of computer.
 Used for scientific research, weather forecasting, and simulations.
7. Embedded Systems
 Specialised computers built into other devices.
 Examples:
 Smart TVs
 Washing machines
 Microwave ovens
 Automobiles
Classification of Computing Devices

Common Features of Computing Devices


 Input: Accept data from users or sensors.
 Processing: Execute instructions using a processor (CPU).
 Storage: Save data and programs.
 Output: Display or communicate results.
 Connectivity: Connect to networks and other devices.
Applications
 Education and learning
 Business and banking
 Communication
 Healthcare
 Scientific research
 Entertainment
 Industrial automation
Computing devices are electronic systems that process information and perform tasks. They
range from smartphones and laptops to powerful servers and supercomputers, playing a vital
role in modern life.

Identification of Computational Problems


Definition:-
Identification of computational problems is the process of recognizing and defining
problems that can be solved using a computer. It involves understanding the problem,
determining the required inputs and outputs, and deciding how a computer can be used to
find a solution.
What is a Computational Problem?
A computational problem is a problem that can be solved through a sequence of steps (an
algorithm) executed by a computer.
Examples
 Calculating student grades.
 Finding the largest number in a list.
 Searching for a record in a database.
 Sorting employee details.
 Predicting weather conditions.
Steps in Identifying a Computational Problem
1. Understand the Problem
 Clearly define what needs to be solved.
 Identify the objective of the problem.
Example: Calculate the average marks of a student.
2. Identify Inputs
 Determine the data required to solve the problem.
Example: Marks obtained in different subjects.
3. Identify Outputs
 Determine the expected result.
Example: Average mark.
4. Determine Processing Requirements
 Identify the calculations or operations needed.
Example: Sum of marks ÷ Number of subjects.
5. Define Constraints
 Specify limitations and conditions.
Example: Marks must be between 0 and 100.
6. Check Feasibility
 Ensure the problem can be solved using computational methods and available
resources.
Problem Identification Process
Characteristics of a Computational Problem
1. Clearly Defined Inputs
 Data required for solving the problem.
2. Clearly Defined Outputs
 Expected results are known.
3. Algorithmic Solution
 A step-by-step procedure can be developed.
4. Computability
 The problem can be solved by a computer in a finite number of steps.
5. Efficiency
 The solution should use reasonable time and resources.
Example Problem:
Find the largest number among three numbers.
Inputs:
 Three numbers: A, B, C
Processing:
 Compare A, B, and C.
Output:
 Largest number.
Algorithm:
1. Read A, B, and C.
2. Compare the numbers.
3. Display the largest number.
Applications
 Software development
 Data analysis
 Scientific computing
 Artificial Intelligence
 Business automation
 Database management
Instructions:
In computing, an instruction is a single, fundamental command given to a computer's
processor (CPU). It directs the hardware to perform a specific action, such as adding two
numbers or moving data between memory and registers. At the lowest level, instructions are
represented as binary sequences of 1s and 0s.
The Structure of an Instruction
A machine-level instruction typically consists of three parts:
 Operation Code (Opcode): Specifies exactly what the processor needs to do (e.g.,
ADD, LOAD, STORE).
 Operands/Address: Indicates where the data is stored or identifies the registers
involved in the operation.
 Addressing Mode: Defines how the CPU should interpret the address to find the data.
Core Categories of Instructions
Instructions generally fall into four main categories:
 Data Transfer Instructions: Move data between memory and CPU registers (e.g.,
LOAD, STORE).
 Arithmetic and Logic Instructions (ALU): Perform math (e.g., addition, subtraction)
and logical comparisons (e.g., AND, OR).
 Control Flow Instructions: Dictate the order of execution, enabling the computer to
make decisions, jump to different parts of the code, or create loops (e.g., JUMP,
BRANCH).
 Input/Output (I/O) Instructions: Transfer data between the computer and external
devices like keyboards or displays.

Pseudo code
Defination
"Pseudocode is a compact and informal high-level description of an algorithm that uses the
structural conventions of a programming language. It facilitates designers to focus on the
logic of the algorithm."
Pseudocode is an outline of a program written in simple English statements and structured
like a programming language. It is mainly intended for humans to read and understand and is
not executable by a computer. Pseudocode allows programmers to concentrate on the logic
and sequence of steps required to solve a problem without worrying about the syntax of a
specific programming language. It serves as an intermediate step between an algorithm and
an actual program, making program design easier and improving communication among
programmers and system designers.
Characteristics of Pseudocode
 Written in simple English statements.
 Uses programming structures such as IF, ELSE, WHILE, and FOR.
 Independent of any programming language.
 Focuses on problem-solving logic rather than syntax.
 Cannot be executed directly by a computer.
General Format of Pseudocode
1. Start
2. Read/Input data
3. Process the data
4. Display/Print the result
5. End
Example 1: Write a Pseudocode for calculating the price of a product After Adding
Sales Tax to its original price.
Solution
1. Read the price of the product
2. Read the sales tax rate
3. Calculate sales tax = price of the item × sales tax rate
4. Calculate total price = price of the product + sales tax
5. Print total price
6. End

Flowchart
A flowchart is a graphical or symbolic representation of a process. It is basically used to
design and document virtually complex processes to help the viewers visualize the logic of
the process so that they can gain a better understanding of the process and find flaws,
bottlenecks, and other less obvious features within it.

Fig:- Symbols of flowchart


Symbols Used in a Flowchart
1. Start/End Symbol (Terminal Symbol)
 Represents the beginning and end of a flowchart.
 Usually represented by an oval or rounded rectangle.
2. Arrow (Flow Line)
 Shows the flow of control in the program.
 Indicates the sequence of execution of instructions.
3. Processing Symbol
 Represented by a rectangle.
 Indicates calculations, assignments, and processing activities.
4. Input/Output Symbol
 Represented by a parallelogram.
 Used to receive input from the user or display output.
5. Decision Symbol
 Represented by a diamond.
 Used to depict Yes/No or True/False conditions.
 Has one incoming arrow and two outgoing arrows.
6. Connector Symbol
 Used to connect different parts of a flowchart.
 Helps avoid too many crossing flow lines.

Significance of Flowcharts
 A flowchart is a diagrammatic representation that illustrates the sequence of steps
required to solve a problem.
 It is useful during all stages of formulating computer solutions.
 It facilitates communication between programmers and users.
 Once drawn, programmers can understand the solution easily and clearly.
 Flowcharts help programmers understand the logic of complicated and lengthy
problems.
 They make it easier to write programs in a high-level programming language.
 Flowcharts provide better documentation of complex programs.
 A flowchart follows a top-down approach in solving problems.
Advantages of Flowcharts
1. They are very good communication tools to explain the logic of a system.
2. They help analyze problems more effectively.
3. They are useful for program documentation, especially for complex programs.
4. They act as a guide or blueprint for programmers while coding.
5. They help programmers follow the program flow from start to end without missing
any step.
6. They can be used to debug programs and help detect, locate, and remove errors
systematically.
Limitations of Flowcharts
1. Drawing flowcharts is laborious and time-consuming, especially for large programs.
2. For complex programs, flowcharts can become complicated to understand.
3. Even small changes in a program may require redrawing the entire flowchart.
4. Important details may get lost while representing the problem graphically.
5. There are no well-defined standards that limit the amount of detail to be included in a
flowchart.
Types of Flowcharts
Three types of Flowcharts are listed below:
 Process Flowchart: This type of Flowchart shows all the activities that are involved
in making a product. It provides a pathway to analyze the product to be built. It is most
commonly used in process engineering to illustrate the relation between the major as
well as minor components present in the product. It is used in business product
modelling to help employees understand the project requirements and gain some
insight into the project.
 Data Flowchart: It is used to analyse the data, specifically, it helps in analysing the
structural details related to the project. Using this Flowchart, one can easily
understand the data inflow and outflow from the system. It is most commonly used to
manage data or to analyse information to and out of the system.
 Business Process Modelling Diagram: Using this Flowchart or diagram, one can
analytically represent the business process and help simplify the concepts needed to
understand business activities and the flow of information. This Flowchart illustrates
the business process and models graphically which paves the way for process
improvement.
Example 1: Draw a flowchart to calculate the sum of the first 10 natural numbers.
Example2: Draw a flowchart to add two numbers.

Algorithms
Definition
An algorithm is a blueprint for writing a program to solve a particular problem. It is a well-
defined sequence of instructions that solves a problem in a finite number of steps.
An algorithm gives the logic of a program, that is, a step-by-step description of how to arrive
at a solution.

Characteristics of an Algorithm
A sequence of instructions must possess the following characteristics to qualify as an
algorithm:
1. Be precise – Instructions must be unambiguous.
2. Be unambiguous – Each step should have only one meaning.
3. Not even a single instruction must be repeated infinitely – The algorithm must
terminate.
4. After the algorithm gets terminated, the desired result must be obtained – It
should produce the correct output.

Building Blocks of Algorithms


An algorithm has a finite number of steps, and some steps may involve decision making and
repetition. Broadly speaking, an algorithm may employ three control structures, namely
Sequence, Decision, and Repetition. These are known as the building blocks of
algorithms because every algorithm is constructed using one or more of these basic
structures.
Sequence
Sequence means that each step of the algorithm is executed in the specified order. In this
control structure, instructions are performed one after another without any change in the flow
of execution. Every step is executed exactly once in the order in which it appears.

For example, an algorithm to add two numbers first reads the numbers, then computes their
sum, and finally displays the result. Thus, the algorithm follows a purely sequential order.

Decision

Decision statements are used when the outcome of a process depends on some condition. A
condition is a statement that evaluates to true or false. If the condition is true, one set of
instructions is executed; otherwise, another set is executed.
The most common decision construct is the if-else statement. Decision structures help the
algorithm choose between alternative courses of action based on the given condition.

Fig: Algorithm to test the equality of two numbers

Repetition

Repetition involves executing one or more steps a number of times. It is used when certain
instructions need to be performed repeatedly until a specified condition is satisfied.
Repetition can be implemented using constructs such as while, do-while, and for loops. For
example, an algorithm that prints the first ten natural numbers repeatedly executes the print
statement until all ten numbers have been displayed.

The three control structures—Sequence, Decision, and Repetition—form the fundamental


building blocks of algorithms. They determine the flow of execution within an algorithm and
enable the systematic solution of problems. By combining these structures, complex
algorithms can be designed efficiently and effectively

Different Approaches to Designing an Algorithm


For a complex problem, an algorithm is often divided into smaller units called modules. This
process is known as modularization.
Advantages of Modularization
 Makes the complex algorithm simpler to design and implement.
 Each module can be designed independently.
 Simplifies implementation, debugging, testing, documentation, and maintenance.

Top-Down Approach
 Begins by dividing the complex algorithm into one or more modules.
 These modules are further decomposed into sub-modules.
 This process continues until the desired level of detail is achieved.
 It follows a process called stepwise refinement.

Bottom-Up Approach
 Reverse of the top-down approach.
 Starts with designing the most basic or concrete modules.
 Higher-level modules are formed by combining lower-level modules.
 The process continues until the complete algorithm is obtained.

Example 1: Write an algorithm to find the larger of two numbers.


Example 2: Write an algorithm to find whether a number is even or odd.

Introduction to Python Programming:


Python is a high-level, interpreted, and general-purpose programming language that was
developed by Guido van Rossum and released in 1991. It is designed to be simple, easy to
read, and user-friendly. Python uses an English-like syntax, making it one of the most
popular programming languages for beginners as well as professional programmers.
Python is an interpreted language, which means that programs are executed line by line
without the need for compilation. This feature makes program development, testing, and
debugging easier and faster. Python is also platform-independent, allowing the same program
to run on different operating systems such as Windows, Linux, and macOS without
modification.
Python supports multiple programming paradigms, including procedural, object-oriented,
and functional programming. It provides a large standard library and numerous modules that
help programmers develop applications efficiently. Due to its simplicity and extensive
features, Python is widely used in web development, data science, artificial intelligence,
machine learning, automation, scientific computing, and software development.
Because of its readability, flexibility, and powerful libraries, Python has become one of the
most widely used programming languages in both academia and industry. It enables
programmers to solve complex problems with fewer lines of code, making software
development faster and more productive.

History of Python
Python was developed by Guido van Rossum in 1991 at the Center for Mathematics and
Computer Science (CWI) in the Netherlands, a research institute managed by the Dutch
government. While working on system utilities in the C programming language, Van Rossum
frequently interacted with the Bourne Shell in the Unix operating system.
During this work, he realized the need for a programming language that could bridge the gap
between the complexity of the C language and the simplicity of shell scripting. He wanted to
create a language that was easy to learn, powerful, and suitable for solving a wide variety of
programming problems. This idea led to the development of Python.
Van Rossum chose the name "Python" from the British television comedy show Monty
Python's Flying Circus. Contrary to popular belief, the language was not named after the
snake but after this television show, which he enjoyed.
The first working version of Python was completed in early 1990, and it was officially
released to the public on February 20, 1991. Since then, Python has undergone continuous
development and has evolved into one of the most widely used programming languages in
the world.
Python is an open-source programming language, which means that anyone can freely
download, use, and modify it according to their requirements.
The Python logo consists of two intertwined snakes, symbolizing the language's name and
its simplicity and flexibility. Today, Python is extensively used in web development, data
science, artificial intelligence, machine learning, automation, and scientific computing.

Features of Python:
The following are some of the important features of Python that have gained the popularity
of the language in the programming community.
Simple: Python is a simple programming language. It means more clarity and less stress on
understanding the syntax of the language. Hence, developing and understanding programs
will become easy.
Easy to learn: Python uses very few keywords. Its programs use a very simple structure. So
developing programs in Python becomes easy. Also, Python resembles the C language. Most
of the language constructs in C are also available in Python. Hence, migrating from C to
Python is easy for programmers.
Open Source: There is no need to pay for Python software. Python can be freely
downloaded from the [Link] website. Its source code can be read, modified and
used in programs as desired by the programmers.
High-Level Language: programming languages are of two types: low-level and high-level.
A low-level language uses machine code instructions to develop programs. These
instructions directly interact with the CPU. Machine language and assembly language are
called low-level languages. High-level languages use English words to develop programs.
These are easy to learn and use. Python also uses English words in its programs, and hence it
is called a high-level programming language.
Dynamically typed: In Python, we need not declare anything. An assignment statement
binds a name to an object, and the object can be of any type. If a name is assigned to an
object of one type, it may later be assigned to an object of a different type, i.e., Python is a
dynamically typed language.
Platform Independent: Many Python programs are compiled using a Python compiler,
which generates byte code. Python bytecode represents a fixed set of instructions that run on
all operating systems and hardware. Using a Python virtual machine PVM anybody can run
these bytecode instructions on any computer system. Hence, Python programs are not
dependent on any specific operating system.
Portable: if your program will produce the same result on any computer in the world, then it
is called a portable program. Python programs will give the same result since they are
platform-independent. Once the protection program is written, it can run on any computer
system using PVM. However, Python also contains some system-dependent modules that are
specific to the operating system.
Procedures and object-oriented: Python is a procedure-oriented as well as an object-
oriented programming language. In procedure-oriented programming languages, the
programs are built using functions and procedures, but in object-oriented languages, the
programs use classes and objects. In Python language, everything like variables, lists,
functions, arrays etcetera are treated as objects.
Interpreted: Python is an interpreted programming language. The program written by the
programmer is called the source code. After writing a Python program, the source code is
first translated into an intermediate code called bytecode by the Python compiler. This
bytecode is then executed by the Python Virtual Machine (PVM). Inside the PVM, an
interpreter translates the bytecode into machine code, which is understood by the processor
and produces the desired output.
Extensible: The programs or pieces of code written in C or C++ can be integrated into
Python and executed using the Python Virtual Machine (PVM). This feature is available in
standard Python. Other flavours of Python allow programs written in other programming
languages to be integrated into Python. For example, Jython enables Java code to be
integrated into a Python program and executed on the Java Virtual Machine (JVM).
Embeddable: we can insert a Python program into a C or C++ program. Several
applications are already developed in Python,which can be integrated into other
programming languages like C or C++, Delphi, PHP, Java and .Net. It means programmers
can use these applications for their advantage in various software projects.
Huge Library: Python has a big library which can be used on any operating system, like
Unix, windows, or Macintosh. Programmers can develop programs very easily using the
modules available in the Python library.
Scripting language: Scripting language is a programming language that does not use a
compiler for executing the source code. Rather, it uses an interpreter to translate the source
code into machine code. Generally, scripting languages perform supporting tasks for bigger
applications or software. Python is considered a scripting language as it is interpreted, and it
is used on the Internet to support other software.
Database connectivity: A database represents a software that stores and manipulates data.
For example, Oracle is a popular database that we can use to store data in tables and
manipulate it. Python provides interfaces to connect its programs to all major databases like
Oracle, Sybase or MySQL.
Scalable: The program would be scalable if it could be moved to another operating system
or hardware and take full advantage of the new environment in terms of performance. Python
programs are scalable since they can run on any platform and use the features of the new
platform effectively.
Batteries included: the huge library of Python contains several small applications which are
already developed and immediately available to programmers. These small packages can be
used and maintained easily. Thus, the programmers need not download separate packages or
applications in many cases. This will give them a head start in many projects ,these libraries
are called batteries included. Examples of these packages are argparses, botois, cherry py,
cryptography, Fiona, jellyfish etc.

You might also like