0% found this document useful (0 votes)
20 views24 pages

Module 1_Lecture 1 Algorithm and Flowchart

Uploaded by

u.navya25
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
20 views24 pages

Module 1_Lecture 1 Algorithm and Flowchart

Uploaded by

u.navya25
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 24

Problem Solving Using

Python
(ITFC0101)
Dr. Kusum Kumari Bharti
Course Outline/Curriculum & Lecture/Tutorial Count

Module
Topics
No.

Computational Thinking and Problem-Solving: Identification of Computational Problems -Algorithms,


building blocks of algorithms (statements, state, control flow, functions), notation (pseudo code, flow
chart, programming language), algorithmic problem solving, simple strategies for developing algorithms
1 (iteration, recursion).
Data Types, Expressions, and Statements: Python interpreter and interactive mode, debugging; values
and types: int, float, Boolean, string, and list; variables, expressions, statements, tuple assignment,
precedence of operators, comments.
Control Flow Functions, and Strings: Conditions - Boolean values and operators, conditional (if),
alternative (if-else), chained conditional (if-elif-else); Iteration - state, while, for, break, continue, pass;
2
Fruitful functions - return values, parameters, local and global scope, function composition, recursion;
Strings - string slices, immutability, string functions and methods, string module; Lists as arrays.
Lists, Tuples, Dictionaries: Lists - list operations, list slices, list methods, list loop, mutability, aliasing,
cloning lists, list parameters; Tuples - tuple assignment, tuple as a return value; Dictionaries - operations
3 and methods; advanced list processing, list comprehension.
Files, Modules, Packages: Files and exceptions: text files, reading and writing files, format operator;
command line arguments, errors and exceptions, handling exceptions, modules packages.
Evaluation Criteria

S.
Evaluative Components and tentative dates of examination Marks
No.
Mid Sem Examination
1 30

End Term Examination


2 50

3 Teachers Assessment (Attendance, Quizzes and Assignments) 20

Total 100
Need of the programming language
• Enable communication with computers and execution of tasks.
• Facilitate software development and feature implementation.
• Support a wide range of applications, from web to mobile to systems
programming.
• Offer tools for efficiency, performance, and resource management.
• Provide frameworks and libraries to streamline development.
• Foster problem-solving, innovation, and custom solutions.
• Support cross-platform and compatible development.
• Apply to various fields including science, finance, and business.
• Enhance career skills and educational opportunities.
• Encourage community involvement and open-source contributions.
Steps for writing program
Writing a program involves several systematic steps to ensure that the software is
well-designed, functional, and efficient
– Understand the Problem: Define requirements and constraints.
– Plan the Solution: Design the algorithm or solution approach.
– Choose a Programming Language: Select the appropriate language for the task.
– Set Up the Development Environment: Install and configure tools and environment.
– Write the Code: Implement the algorithm in code.
– Test the Program: Run tests and debug issues.
– Optimize the Code: Improve performance and refactor as needed.
– Document the Code: Add comments and create necessary documentation.
– Deploy the Program: Prepare and release the program to users.
– Maintain and Update: Monitor and update the program based on feedback and changing needs.
Steps for writing program

• Algorithm
• Pseudo code
• Flowchart
• Program
Algorithm
• First algorithm was written by Ada Lovelace in year 1843.

• She is often credited with writing the first algorithm intended for
implementation on a computer.

• Her notes included an algorithm for the Analytical Engine to compute


Bernoulli numbers, making her the world’s first computer programmer.

• An algorithm is a step-by-step procedure or set of instructions designed to


perform a specific task or solve a particular problem.

• It outlines the logical sequence of operations and decisions needed to


achieve a desired result.
Example of Algorithm (Sum of Two Numbers)

1. Read two numbers, A and B.


2. Calculate the sum: sum = A + B.
3. Output the sum.
Algorithm
Example
Step 1: Get dressed to go the market
Step 2: Check your wallet for money
Step 3: If there is no money in the wallet, replenish it.
Step 4: Go to the shop
Step 5: Ask for your favorite brand of pen
Step 6: If pen is available, go to step 7 else go to step 10
Step 7: Give money to the shopkeeper
Step 8: Keep the purchased pen safely
Step 9: Go back home
Step 10: Ask for any other brank of pen
Step 11: Go to step 7
Characteristics -Algorithm
• Abstract and General: Algorithms are conceptual and not tied to any
specific programming language or syntax.

• Descriptive: They describe the problem-solving process in a way that


can be understood without code.

• Structured: Algorithms typically include steps, decisions, and loops.


Algorithm for Prime number

1. Take a number n
2. If the number n is less than or equal to 1, it is not a prime
3. If number n is 2 or 3, it is prime
4. If n is even and greater than 2, it is not a prime
5. For each integer i to n-1, check if n is divisible by i. If n is divisible by any i,
then n is not prime.
Algorithm for Prime number

1. Take a number n
2. If the number n is less than or equal to 1, it is not a prime
3. If number n is 2 or 3, it is prime
4. If n is even and greater than 2, it is not prime
5. For odd numbers greater than 3, check if the number is divisible by any
integer from 3 up to sqrt(n). If it is divisible by any of these is is not prime.
check if n is divisible by i. If n is divisible by any i, then n is not prime.
Pseudocode

• It is an informal way of programming


• Pseudocode is a way of representing an algorithm using a mixture of
natural language and programming-like constructs.
• It is a bridge between human-readable descriptions and actual code.
Pseudocode

Pseudocode SumOfTwoNumbers

Input: Two numbers A and B


Output: The sum of A and B.

1. Read A
2. Read B
3. sum = A + B
4. Print sum
Start
// Input section
1. Prompt the user to enter the first number
2. Read the first number and store it in variable A
3. Prompt the user to enter the second number
4. Read the second number and store it in variable B
5. // Processing section
6. Calculate the sum of A and B
7. Store the result in variable sum
8. // Output section
9. Print the value of sum
End
Characteristics - Pseudocode

• Simplified Syntax: Uses a structure similar to programming languages but


with less formal syntax.

• Language-Agnostic: It is not tied to any specific programming language


and focuses on the logic rather than the syntax.

• Readable: Designed to be easily understandable by humans, making it a


useful tool for planning and discussion.
Algorithm

Algorithm SumOfTwoNumbers Pseudocode SumOfTwoNumbers

Input: Two numbers A and B


Input: Two numbers A and B Output: The sum of A and B.
Output: The sum of A and B.
1. Start
1. Read two numbers, A and B. 2. Read A
3. Read B
2. Calculate the sum: sum = A + B.
4. sum = A + B
3. Output the sum. 5. Print sum
6. End
Comparison
•Purpose:
•Algorithm: Focuses on defining the steps to solve a problem or perform a task.
•Pseudocode: Provides a readable way to write out the algorithm using a format that resembles
code.

•Level of Detail:
•Algorithm: Generally more abstract and conceptual, without specific syntax.
•Pseudocode: More detailed and structured, resembling code but not bound by syntax rules.

•Use:
•Algorithm: Used for conceptualizing and designing solutions before coding.
•Pseudocode: Used for planning and explaining algorithms in a way that can be easily translated
into actual code.

•Language Dependence:
•Algorithm: Independent of programming languages.
•Pseudocode: Designed to be translated into code and uses language-like constructs for clarity.
• Algorithm: A high-level description of steps to solve a problem.
• Pseudocode: A detailed, human-readable way to describe an algorithm that
resembles programming language syntax but is not actual code.
Flowchart

A flowchart diagram is a graphical representation of the series of steps to run a


program.
In other words, a flow chart is the graphical form of an algorithm.

Three types of flowchart


i. Process flowchart
ii. Data flowchart
iii. Business process modelling
Flowchart

The oval symbol in The rectangle symbolizes the guide your audience Indicate that a
flowcharts represents the process steps involved in the along the flowcharting decision point
start and end of the process. diagram journey
It is commonly used to
indicate the beginning and Parallelogram is
conclusion of the flowchart. used to represent
input and
Output data
Types of business flowchart
• Decision flowchart. Your business can use this diagram if you want to justify decisions.
Creating the flowchart allows you to anticipate the possible consequences of various
choices.

• Logic flowchart. This flowchart is used to uncover bottlenecks and loopholes which could
cause issues or disruptions.

• Product flowchart. Companies can develop a product flowchart to illustrate the processes
of product creation. The diagram is also helpful when your business is launching a new
product or improving production processes.

• Process flowchart. This shows how a specific process can achieve the desired outcomes.
In most cases, the process flowchart is essential for teams who opt to improve current
processes.

You might also like