Pseudocode and Python Flashcards
How to assign values to variables the add to those values then display them to the screen.
SET score TO 5
SET score TO score + 12
SEND score TO DISPLAY
How to concatenate strings ( join two or more strings together to make a new text string.)
SET displayName to firstName & surname.
use the ampersand
IF AND ELSE statements
IF condition THEN action END IF
IF condition THEN action_a ELSE action_b END IF
IF condition_1 THEN action_a ELSE IF condition_2 THEN action_b END IF
Complex Conditions
AND – both conditions must be true e.g. gender = “M” AND age > 18
OR – either of the conditions must be true e.g. class = 1 OR class = 3
NOT – the condition should not be true e.g. NOT (gender = “M”)
What is a Fixed Loop?
When a group of instructions is repeated a pre-determined number of times.
FOR counter 0 TO 5 DO
SEND “All work and no play makes Jack a dull boy” TO DISPLAY
End For
What is a Conditional Loop?
Will keep repeating a group of instructions until a specific conditional is met. GET password FROM (STRING) KEYBOARD WHILE password != “letmein” DO SEND “In-correct” TO DISPLAY GET password FROM (STRING) KEYBOARD END WHILE
What are the three Predefined functions?
Round – rounds a value to a specific number of decimal places.
SET pi TO 3.141592
SET pi TO ROUND (pi, 2) → the new value of pi will be 3.14
Length – give the number of character present in a variable.
SET word TO “Mississippi”
SET numWord TO LENGTH (word) → the value of numWord would be 11
Random – generates a random number, between a lower and upper range.
SET bonusBall to RANDOM (1,59)
What is the round predefined function?
Round – rounds a value to a specific number of decimal places.
SET pi TO 3.141592
SET pi TO ROUND (pi, 2) → the new value of pi will be 3.14
What is the length predefined function?
give the number of character present in a variable.
SET word TO “Mississippi”
SET numWord TO LENGTH (word) → the value of numWord would be 11
What is the random predefined function?
generates a random number, between a lower and upper range.
SET bonusBall to RANDOM (1,59)
A program must ensure the user enters a number between 1 & 100. Please write the code in pseudocode for this program.
GET score FROM (INTEGER) KEYBOARD WHILE score < 1 or score > 100 DO SEND “In-Valid” TO DISPLAY GET score FROM (INTEGER) KEYBOARD END WHILE
A program must calculate the total cost of 5 items. Please write the code in pseudocode for this program.
SET total TO 0 FOR counter 0 TO 5 GET itemPrice FROM (REAL) KEYBOARD SET total = total + itemPrice END FOR
A program is required to count all A grades. Please write the code in pseudocode for this program.
SET grade TO [A, B, C, A, A, B, A, C] SET numA TO 0 FOR counter 0 TO 7 IF grade[counter] == “A” THEN numA = numA + 1 END FOR