PSEUDOCODE and PYTHON PROGRAMMING Grade 8
PSEUDOCODE and PYTHON PROGRAMMING Grade 8
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)
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)
BEGIN
READ radius r
INITIALIZE
pi=3.14
CALCULATE Area=pi * r *r
PRINT Area
END
Python Code:
import math
BEGIN
READ n
INITIALIZE i to 1
FOR i <= n, then
DISPLAY i
INCREMENT i
END FOR
END
Python Code:
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")
START
INPUT num1, num2, num3
SET sum = num1 + num2 + num3
SET average = sum / 3
OUTPUT average
STOP
Python Code:
START
INPUT string
SET reversed_string = REVERSE(string)
OUTPUT reversed_string
STOP
Python Code:
START
FOR i = 10 TO 1 STEP -1
OUTPUT i
NEXT i
STOP
Python Code:
START
INPUT celsius
SET fahrenheit = (celsius * 9/5) + 32
OUTPUT fahrenheit
STOP
Python Code:
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")