










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Lesson Outline
Sequence
a = 15 b = 10 Total = a + b Print “Total = “, Total Pseudocode a = 15 # An integer assignment b = 10 # An integer assignment total = a + b # Calculating the total print (“Total = “, total)
Selection Selection control structure
if and else statement Num = 15 Print Num, Type If Num % 2= No Yes Type = “EVEN” Type = “ODD” Num = 15 IF Num % 2 = 0 THEN Type = “EVEN” ELSE Type = “ODD” END IF Print Num, Type Pseudocode Num^ =^10 if Num % 2 == 0 : Type = ”EVEN” else: Type = ”ODD” print (Num,” is “,Type)
Nested if statement Marks = 50 if Marks >= 80 : Grade = ”Distinction” elif Marks >= 60 : Grade = ”Credit” elif Marks >= 40 : Grade = ”Pass” else: Grade = ”Fail” print(“You got a “,Grade) Marks = If Marks >= 80 Yes No (^) Grade = “D” Print Grade If Marks >= 60 Grade = “C” If Marks >= 40 Grade = “F” Grade = “P” No No Yes Yes Marks = 50 IF Marks > = 80 THEN Grade = “Distinction” ELSE IF Mark >= 60 THEN Grade = “Credit” ELSE IF Mark >= 40 THEN Grade = “Pass” ELSE Grade = “Fail” END IF END IF END IF Print Grade Pseudocode
Switch statement Code = 1 Case Code = 1 Yes No (^) Color = “Red” Print Color Case Code = 2 Color = “Green” Case Code = 3 Color = “White” Color = “Blue” No No Yes Yes Code = 1 CASE OF Code 1 : Color = ”Red”; BREAK : 2 : Color = ”Green”; BREAK ; 3 : Color = ”Blue”; BREAK ; DEFAULT : Color = “White” END CASE Print Color Pseudocode
Repetition
For loop Total = 0 for x in range ( 1 , 6 ): print (“x = “,x) Total = Total + x print(“Total = “,Total) FOR x = 1 TO 5 STEP 1 Print x Total = Total + x END FOR Print Total Pseudocode For x = 1 to 5 No Yes print x Total = Total + x Print Total
Do while loop x = 1 DO Print x Total = Total + x x = x + 1 WHILE x <= 5 Print Total Pseudocode While x <= 5 False True print x Total = Total + x Print Total x = x + 1 x = Python doesn’t support do while loop.
Repeat / until loop x = 1 REPEAT Print x Total = Total + x x = x + 1 UNTIL x > 5 Print Total Pseudocode Until x > 5 True False print x Total = Total + x Print Total x = x + 1 x = Python doesn’t support Repeat / until loop.
Recursion