Exam Reference Sheet
Instruction Explanation
Assignment, Display, and Input
Tex t :
a ← expression
Block:
a
expression
Evaluates expression and then assigns a copy of the result to
the variable
a.
Tex t :
DISPLAY(expression)
Block:
DISPLAY expression
Displays the value of expression, followed by a space.
Tex t :
INPUT()
Block:
Accepts a value from the user and returns the input value.
Arithmetic Operators and Numeric Procedures
Text and Block:
a + b
a - b
a * b
a / b
The arithmetic operators +, -, *, and / are used to perform
arithmetic on
a and b.
For example,
17 / 5 evaluates to 3.4.
The order of operations used in mathematics applies when evaluating
expressions.
Text and Block:
a MOD b
Evaluates to the remainder when a is divided by b. Assume that
a is an integer greater than or equal to 0 and b is an integer
greater than
0.
For example,
17 MOD 5 evaluates to 2.
The
MOD operator has the same precedence as the * and /
operators.
Tex t :
RANDOM(a, b)
Block:
b
Generates and returns a random integer from a to b, including
a and b. Each result is equally likely to occur.
For example,
RANDOM(1, 3) could return 1, 2, or 3.
Relational and Boolean Operators
Text and Block:
a = b
a ≠ b
a > b
a < b
a ≥ b
a ≤ b
The relational operators =, ≠, >, <, ≥, and ≤ are used to test
the relationship between two variables, expressions, or values. A
comparison using relational operators evaluates to a Boolean value.
For example,
a = b evaluates to true if a and b are
equal; otherwise it evaluates to
false.
AP Computer Science Principles
Exam Reference V.1
|
1
Return to Table of Contents