Docsity

Basics of Programming Part 1, Lecture notes of Programming Languages

Partial preview of the text

Download Basics of Programming Part 1 and more Lecture notes Programming Languages in PDF only on Docsity!

Introduction to Programming and Python Basics

Unit I

1.1. Problem-solving and

computational thinking

1.2. Programming Paradigm -

Structural Programming and

Object-Oriented Programming

1.3. Algorithms,

pseudocode and

flowcharts

1.4. Python environment,

running scripts, basic

input/output

1.5. Debugging mindset

(reading errors, using

print/debug tools)

1.1. Problem-solving and computational thinking

Four Pillars

1.Decomposition

4. Algorithmic

Design

Breaking down a complex problem

into smaller, manageable sub-

problems.

Developing a step-by-step rule or

formula to solve the problem.

3. Abstraction

Focusing only on the important details

and filtering out unnecessary

information..

2. Pattern

Recognition

Identifying similarities or trends

within the problem or past

problems.

Computational thinking is a method of breaking down complex problems into

smaller, manageable steps that a computer can understand and execute

Algorithm

Coding Concept Sub - Concepts

Algorithm

●

Definition of algorithm

●

Characteristics of an algorithm

●

Examples of algorithm

● Design algorithm for simplifying problems

Concept Overview

Algorithm (cont.)

Example

Algorithms turn ideas into

clear steps and solutions

into reality.

To provide

a straightforward

explanation of how it

works without getting

into too technical.

5

Importance of Algorithm

To find a solution for

the problem.

1

To understand

the core idea behind

a problem.

3

To understand the flow

of the problem.

2

To break down a

complex problem into

smaller and more

manageable steps.

4

What is Pseudocode?

Pseudocode is a simple, human-readable way to

describe the steps of an algorithm without using the

strict syntax of any programming language.

Why Used Pseudocode?

Easy to Understand

Focuses on logic, not syntax

Helps plan programs

before coding

Makes it easier to

explain algorithms to

others

Key Feature

Examples

Step Algorithm

1 START.

Read any two numbers(x and y).

3 Average = (x+y)/2.

4 Display Average.

5 STOP/End.

Write an algorithm to find the average of any two numbers

entered by the user and display the result.

Solution

Activity 2 - Multiplying Two Numbers

Solution

Write an algorithm to

multiply any two

numbers and display

the result.

Step Algorithm

1 START.

2 Take input for x and y.

3 Multiply = x *^ y.

4 Display Multiply.

5 STOP.

Activity 4 - Perimeter of Rectangle

Solution

Write an algorithm in your notebook

to find the perimeter of a rectangle

and display the perimeter.

Step Algorithm

1 START.

2 Read a length and width (l, w).

perimeter = 2*(l+w) or perimeter

= l+w+l+w.

4 Display perimeter.

5 STOP.

Activity 5 - Eligibility for voting

Write an algorithm in your notebook

to check whether a person is eligible

to cast a vote using the following

criteria:

1.If the age is 18 and above, then

display a message ‘Eligible to vote’

2.Otherwise display a message, ‘Not

eligible to vote.’

Solution

Step Algorithm

1 START.

2 Read the age.

3 Check if age>= 18, then got to step 4

4 Display ‘Eligible to vote’.

5 Otherwise, display ‘Not eligible to vote’.

6 STOP.

Practice 1 - Greatest Number

Solution

Write an algorithm to find the

greatest of two numbers.

Step Algorithm

1 START

2 Read any two numbers a, b

3 Check if a>b, then go to step 4

4 Display “a is greater than b”

5 Otherwise, Display “b is greater than a”

6 STOP

Practice 2 - Pass or Fail

Solution

Write an algorithm that prompts the

user to input their exam marks and

determines whether they have passed

or failed. The pass mark is 40 out of

Step Algorithm

1 START

2 Enter a mark [m]

3 Check if m>=40, then go to step 4

4 Display ”Passed”

5 Otherwise, Display “Failed”

6 STOP