4. Sequence

Sequence is one of the three basic control structures.
A sequence is a control structure that consists of a set of instructions like a recipe.
Every line of code in the sequence is run in the order that it is written.
Pseudocode typically starts with BEGIN and ends with END.
Python - Pseudocode equivalents

Python

Pseudocode

=

print

OUTPUT or PRINT or DISPLAY

input

INPUT or GET


4.1. Input and output

The code below prompts the user to enter their name, then prints a greeting.
name = input("Enter your name?")
print("Hello, " + name + ". Nice to meet you.")
Pseudocode. The equivalent pseudocode is:
BEGIN
   name ← INPUT ("Enter your name?")
   PRINT "Hello, " + name + ". Nice to meet you."
END

Tasks

  1. Write pseudocode for the python sequence below:

    a = 5
    b = 6
    print(a * b)
    

Write pseudocode for the python sequence.

a ← 5
b ← 6
OUTPUT (a * b)

Tasks

  1. Write python for the pseudocode sequence below. Hint: random.sample(string, k) returns a random list of k characters from the string without replacement.

    BEGIN
       INPUT a number between 1 and 10
       Multiply by 3
       Add 18
       Multiply by 3
       OUTPUT all the digits but 1
    END
    

Write python for the pseudocode sequence.

import random

n = int(input("Enter a number between 1 and 10: "))
n = n * 3
n = n + 18
n = n * 3
n = str(n)
mixed_digits_list = random.sample(n, len(n) - 1)
digits_str = "".join(mixed_digits_list)
print(digits_str)