levo

Fundamentals of Programming

Relational Operations, Constants and Variables

  • 4 things to know
  • Paper 1

Overview

Recall questions on the six relational operations and their symbols, the result they yield, and the distinction between assignment and comparison.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Why is testing two real numbers for exact equality unreliable, and what should you do instead?

Evaluation

A is True and B is False. Evaluate NOT A, A AND B, A OR B and A XOR B.

Key term

Explain the difference between a variable and a constant.

Key term

Give an example of a constant and of a variable, and say why naming a limit helps.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Name the six relational operations and give a symbol commonly used for each.

    Model answer

    Equal to (= or ==), not equal to (!= or <>), less than (<), greater than (>), less than or equal to (<=), and greater than or equal to (>=).

  2. 2

    What is the result of a relational operation, and what is it used for?

    Model answer

    A Boolean value, True or False. That Boolean result is what a selection statement or the condition of a loop tests, and it can also be stored in a Boolean variable or combined with other conditions using Boolean operators.

  3. 3

    Why do many languages use = for one purpose and == for another?

    Model answer

    Because assigning and comparing are different operations. In C#, Java and Python a single = assigns a value to a variable while a double == tests two values for equality; VB.Net uses = for both and works out which is meant from the context. Writing = where == is meant is a common error that either fails to compile or silently changes a variable.

  4. 4

    How do you test that a mark is at least 40 but no more than 69?

    Model answer

    mark >= 40 AND mark <= 69. 'At least' maps to greater than or equal to, and 'no more than' maps to less than or equal to; using the strict < and > operators here would wrongly exclude the boundary values 40 and 69.

  5. 5

    How are two strings compared by the relational operators, and is 'Zoo' less than 'apple'?

    Model answer

    They are compared character by character from the left using the character codes, and the first position where they differ decides the outcome; if one string runs out first it is the smaller. In ASCII the capitals occupy codes 65 to 90 and the lower-case letters 97 to 122, so 'Z' (90) is less than 'a' (97) and therefore 'Zoo' is less than 'apple'. This is why a case-sensitive sort puts all capitalised words before lower-case ones.

  6. 6

    Why is testing two real numbers for exact equality unreliable, and what should you do instead?

    Model answer

    Because reals are stored as an approximation, so a value that should be 0.3 may be held as very slightly more or less and a test for exact equality then fails. Instead test that the difference is smaller than a small tolerance, for example abs(a - b) < 0.000001. Integers are stored exactly, so testing them for equality is perfectly safe.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Fundamentals of Programming, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.