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

Getting Started With Python

The document provides an overview of problem solving in computer science, detailing the steps involved such as analyzing the problem, developing algorithms, coding, testing, and debugging. It introduces Python as a high-level programming language, highlighting its features and modes of operation, including interactive and script modes. Additionally, it explains the representation of algorithms through flowcharts and pseudocode, along with examples for determining even/odd and prime numbers.

Uploaded by

aswin12.eduport
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)
3 views26 pages

Getting Started With Python

The document provides an overview of problem solving in computer science, detailing the steps involved such as analyzing the problem, developing algorithms, coding, testing, and debugging. It introduces Python as a high-level programming language, highlighting its features and modes of operation, including interactive and script modes. Additionally, it explains the representation of algorithms through flowcharts and pseudocode, along with examples for determining even/odd and prime numbers.

Uploaded by

aswin12.eduport
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

Getting Started With Python

Problem and Problem Solving


In computer science, "problem" refers to a task or challenge that
requires a solution. The process of identifying a problem, developing
an algorithm, and implementing an algorithm to develop a computer
program is called Problem Solving. Computers may be used to solve
various daily life problems such as Train Ticket Booking, Online
Shopping and Net-Banking etc.

2
Steps required for solving a problem
- Analyzing the problem

- Developing an Algorithm

- Coding

- Testing and Debugging

3
Analyzing the Problem
This stage focuses on understanding the problem. If we do not have a
clear understanding of the problem, we may develop a computer
program that cannot solve the problem correctly. In this stage, we
figure out the inputs, the outputs and the processing required to
convert the input into the output.

4
Developing Algorithm
This stage focuses on creating a logical sequence of instructions, called
an Algorithm. The algorithm can be executed by a computer to
generate the desired output. An algorithm has a distinct start and end
point, as well as a defined number of steps. For a given problem, more
than one algorithm may be possible and the most suitable algorithm
may be chosen.

5
Algorithm for finding whether a number is Even or Odd

START
Step 1 → Take an integer number A
Step 2 → Divide A by 2 , and store the remainder as r
Step 3 → If r is equal to 0, A is an Even Number
Step 4 → Else it is an Odd Number
STOP

6
Algorithm for finding whether a number is a Prime
number or Not
START
Step 1 → Take an integer number A
Step 2 → Set divisor as 2
Step 3 → Set flag_value as True

Step 4 → Repeat from divisor to A-1

4a. divide A by divisor and store the remainder as r


4b. If 𝑟 is zero, set flag_value to False
4c. Increment divisor by 1
Step 3 → If flag_value is False, A is not prime
Step 4 → Else A is prime
STOP

7
Coding
Coding is the process of creating computer programs.

8
Testing
Testing is a process to check if an application is working as expected
(and not working abnormally). The main objective of Testing is to find
errors.

9
Debugging
Debugging is the activity to fix the errors found in the application
during the testing phase.

10
Representation of Algorithms
There are two common methods of representing an algorithm —
flowchart and pseudocode.

11
Flowchart
- A flowchart is a graphical representation of an algorithm.

- A flowchart contains various shapes which are connected by arrows,


which shows the flow of control.

12
Shapes used in Flowchart

13
Draw a flow-chart to identify whether a number taken as the input
from the user is an even number or an odd number?
Pseudocode
- Pseudocode is a way of representing an algorithm in readable and
easy language.

- Pseudocode is not an actual program. So, it cannot be executed.

- Some of the frequently used keywords while writing pseudocode are


INPUT, COMPUTE, PRINT IF/ELSE, START, STOP

15
Advantages of Pseudo-Code:
1. Easily convertible to a Programming Language

2. Easy to understand and read

16
Write a pseudocode for identifying if a number is even or odd?

INPUT number A
COMPUTE remainder as r = A%2
IF r == 0 PRINT 'Even'
ELSE PRINT 'Odd'
Decomposition
Decomposition is the process of breaking a complex computer problem
into smaller parts that are easily manageable and solvable.

18
Familiarization with the basics of Python
programming
Computer Program:

A computer program is a set of instructions that can be executed by the computer to


perform and solve a certain task. These programs are written in a special language known
as Programming Language.

Computer Programming:

It is the process to create a computer program.

Python Programming Language:

Python is an interpreted, high-level programming language. It was developed by Guido van


Rossum. It is user-friendly and is most popular for its easy-to-use syntax and readable code.
19
Features of Python
• High-level Programming language.

• Interpreted language (as Python programs are executed by an interpreter)

• Easy to use

• Simple Syntax

• Python programs are generally written with fewer Lines of Code as compared to other
programming languages.

• Case-sensitive. For example, 'NUMBER' and 'number' are treated differently in Python.

• Portable programming language - has ability run programs on many computer architectures and
operating systems.

Syntax: Set of rules for framing a valid statement in a programming language. 20


Working in Python
• Install Python on the computer
([Link] Refer Appendix for
installation instructions.

• Use Python IDLE (Integrated Development and Learning


Environment) for developing python Programs.

21
How to Display Data
print( ) function is used to print a message on the screen.

22
A Simple Hello World Program
print("Hello World")

>>> print("Hello World")

Hello World

23
Modes of working in Python
- Interactive Mode

- Script Mode

24
Interactive Mode

In Interactive Mode, a python statement is executed in a command-


line shell. It provides instant feedback for each statement while
keeping prior statements in memory.

25
Script Mode
In script mode, the instructions are saved in a file with a '.py' extension
and executed from the beginning of the file. This mode is suitable for
creating and running large programs. In script mode, all commands
are stored in the form of a program or a script.

26

You might also like