2.2 Programming Constructs

Cards (24)

  • What is the definition of an algorithm?
    An algorithm is a set of instructions presented in a logical sequence.
  • Why do programmers create algorithm designs?
    To plan a program before writing any code and consider potential problems.
  • What are the two main methods of defining algorithms?
    Pseudocode and flowcharts.
  • What is the purpose of the assignment command in programming?
    To assign values to variables.
  • What is the command to take user input in the OCR Exam Reference Language?
    name = input("Enter your name")
  • What does the 'random' command do in programming?
    It generates a random number within a specified range.
  • What is the purpose of the 'if - then - else' selection structure?
    To execute different actions based on a condition.
  • What does the 'for loop' do in programming?
    It repeats a block of code a specified number of times.
  • What is the purpose of a flowchart?
    To visually represent an algorithm.
  • What does the 'substring' method do?
    It extracts a part of a string based on specified indices.
  • What is a trace table used for?
    To track the value of variables as a program runs.
  • What are the basic commands in the OCR Exam Reference Language?
    • Comments: //
    • Assignment: name = "Harold"
    • Constants: constant tax = 15
    • Input/Output: name = input("Enter your name")
    • Casting: str(29), int("102"), float(30), bool("False")
    • Random Number: number = random(1,100)
  • What are the flowchart symbols and their purposes?
    • Terminator: Start/End of the flowchart
    • Process: Represents a process or action
    • Decision: Represents a branching point
    • Input/Output: Represents data input or output
  • What is a sequence?
    Lines of code a the programme will run through
  • What is selection?
    Decision making using if statements
    eg: if age > 16 then
    print()
    else:
    print()
  • What is iteration?
    Repeating code using for or while loops
    • Condition controlled loop (while loop)
    • Count controlled loop (for loop)
  • Variables
    • store data in programs
    • can be changed
  • Constant
    • store data
    • Does not change in value
  • operators
    > greater than
    < less than
    >= greater than or equal to
    <= less than or equal to
    == equal to
    != not equal to
  • MOD
    remainder of division
    e.g : 15 /6 = 3 remainder
  • DIV
    Integer division
    e.g: 7 DIV 2 = 3
  • Logic operators
    AND , both statement must be true to return a true value
    OR , only one statement needs to be true to return a true value
    NOT, the opposite of value
  • Data types
    Character - single symbol or character (e.g t, %)
    String - combination of characters (e.g hi, star)
    Integer - a whole number (e.g 17, 26)
    Real/float - decimal number (e.g 0.5, 678.45)
    Boolean - answer that has only two possible values (e.g true/false, yes / no)
  • Casting
    Changing a variable form one data type to another