0% found this document useful (0 votes)
12 views

PSEUDOCODE and PYTHON PROGRAMMING Grade 8

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)
12 views

PSEUDOCODE and PYTHON PROGRAMMING Grade 8

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
You are on page 1/ 10

PSEUDOCODE and PYTHON PROGRAMMING

DAY 01

Example 1: Write Pseudo code to calculate sum and average for n numbers.

BEGIN
INITIALIZE sum=0, i=1 READ n
FOR i < = n, then
COMPUTE sum = sum +i CALCULATE i=i+1
END FOR
COMPUTE avg = sum/n PRINT sum, avg
END

Python Code:

sum = 0
i=1
n = int(input("Enter a number: "))
for i in range(1, n + 1):
sum += i
avg = sum / n
print("Sum:", sum, "Average:", avg)

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


Example 2: Write Pseudo code to add two numbers.

BEGIN
SET C=0
READ A, B
ADD C=A+B
PRINT C
END

Python Code:

C=0
A = int(input("Enter A: "))
B = int(input("Enter B: "))
C=A+B
print(C)

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


Example 3: Write Pseudo code to calculate area of circle.

BEGIN
READ radius r
INITIALIZE
pi=3.14
CALCULATE Area=pi * r *r
PRINT Area
END

Python Code:

import math

r = float(input("Enter the radius: "))


pi = 3.14
Area = pi * r * r
print("Area:", Area)

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


Example 4: Write Pseudo code to read number n and print the integers counting up to n.

BEGIN
READ n
INITIALIZE i to 1
FOR i <= n, then
DISPLAY i
INCREMENT i
END FOR
END

Python Code:

n = int(input("Enter a number: "))


i=1
while i <= n:
print(i)
i += 1

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


DAY 02
Example 5: Write Pseudo code to find the greatest among two numbers.

BEGIN
Read A, B
IF A >B
PRINT “A is greatest”
ELSE
PRINT “B is greatest”
ENDIF
END

Python Code:

A = int(input("Enter A: "))
B = int(input("Enter B: "))

if A > B:
print("A is greatest")
else:
print("B is greatest")

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


Example 6: Write Pseudo code to calculate the Average of Three Numbers.

START
INPUT num1, num2, num3
SET sum = num1 + num2 + num3
SET average = sum / 3
OUTPUT average
STOP

Python Code:

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
average = (num1 + num2 + num3) / 3
print("The average is:", average)

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


Example 7: Write Pseudo code to Reverse a String.

START
INPUT string
SET reversed_string = REVERSE(string)
OUTPUT reversed_string
STOP

Python Code:

string = input("Enter a string: ")


reversed_string = string[::-1]
print("Reversed string:", reversed_string)

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


Example 8: Write Pseudo code to Count Down from 10 to 1.

START
FOR i = 10 TO 1 STEP -1
OUTPUT i
NEXT i
STOP

Python Code:

for i in range(10, 0, -1):


print(i)

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


DAY 03
Example 9: Write Pseudo code to Convert Celsius to Fahrenheit.

START
INPUT celsius
SET fahrenheit = (celsius * 9/5) + 32
OUTPUT fahrenheit
STOP

Python Code:

celsius = float(input("Enter temperature in Celsius: "))


fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit is:", fahrenheit)

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]


Example 10: Write Pseudo code of Password Validation.

START
SET password = "glenrich"
INPUT user_password
IF user_password == password THEN
OUTPUT "Access Granted"
ELSE
OUTPUT "Access Denied"
STOP

Python Code:

password = "glenrich"
user_password = input("Enter the password: ")
if user_password == password:
print("Access Granted")
else:
print("Access Denied")

THOUHIDUL ISLAM Faculty, CSc Dept. [email protected]

You might also like