Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Chap 2

Pseudo code

A textural representation of an algorithm is called pseudo code.

Ex: For checking the equality of number

Requirements

1. Two numbers

2. Conditional operator ==

Algorithm

Step by Step instruction to solve the particular problem is called algorithm.

Step 1: Start

Step 2: Input number1

Step 3: Input number 2

Step 4: Compare the number

Step 5: display the output

Step 6: Stop

Flowchart

A visual representation of an algorithm is called flowchart.


Start

Password= SMP2

userInput=Enter
your password

No
If password
==userInput

Access
Yes denied

Access granted

Stop

Program-Python
Syntax: Syntax is a defined rule to write a program.

Selection/condition statements:

Selection statements are used to make the decision/choice on the program.


And the decision should be true or false.

1. If statement 2. if else statement 3. Switch statement


Condition operators:

1. == Equal to equal - to check the equality

2. < Less then

3. <= Less then or equal

4. > greater then

5. >= Greater then or equal

6. != not equal

Linear Search/Sequential search:

Linear search is one of the searching algorithm


used in large amount of data sets in order to particular data item using sequential
search.

___________________________________________________________________

Variable/Identifier

Variables are containers for storing data values in the program. Variable
is a name that is used to refer to memory location.

Ex: name=”Ejamaan”

SubjectName=”ICT”

Age=100

Rules for Python variables:

 A variable name must start with a letter or the underscore character


 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
 Variable names are case-sensitive (age, Age and AGE are three different
variables)
 A variable name cannot be any of the Python keywords.

Keywords in Python are reserved words which convey the special meanings to
language compiler(Translator).

Compiler and Interpreter-Both are translator

Compiler:

A compiler translates code from a high-level programming language (like


Python, JavaScript or Go) into machine code before the program runs.

Interpreter:

An interpreter translates code written in a high-level programming


language into machine code line-by-line as the code runs.

Data types: classification of data.

Text Type: Str


Numeric int, float, complex
Types:
Integer are whole numbers
Ex: number=3

Float/real/decimal are whole number with fractional


parts

Ex: weight=73.32

String are used to store the worlds and letters.

Ex: name="virus”
Program to find odd and even number:

Number=3

If(Number%2)==0:

print(“The number is Even ”)

else

print(“The number is odd”)

Program to find the sum of 3 numbers:

Number1=55

Number2=65

Number3=75

Sum=Number1+Number2+Number3

Average=Sum/3

Print(“The average is “+ Average)

Program to find the area :

Length=50

Breadth=60

Area=Length * Breadth

Print(“The area is” + Area)


password="SMP2"
userInput=input(“Enter the password :")

if password == userInput:

print("Access granted")

else:

print("Access denied")

You might also like