# 2.1 Basics

## Enduring Understanding

To find specific solutions to generalizable problems, programmers represent and organize data in multiple ways.

The way statements are sequenced and combined in a program determines the computed result.

## Lesson Objectives

Represent a value with a variable.

Determine the value of a variable as a result of an assignment.

Express an algorithm that uses sequencing without using a programming language.

Represent a step-by-step algorithmic process using sequential code statements.

Evaluate expressions that use arithmetic operators.

Represent a string using a variable.

Evaluate expressions that manipulate strings.

Represent a list using a variable.

For list operations:

Write expressions that use list indexing and list procedures.

Evaluate expressions that use list indexing and list procedures.

For relationships between two variables, expressions, or values:

Write expressions using relational operators.

Evaluate expressions that use relational operators.

For relationships between Boolean values:

Write expressions using logical operators.

Evaluate expressions that use logic operators.

For generating random values: a. Write expressions to generate possible values. b. Evaluate expressions to determine the possible results.

## Essential Knowledge

A variable is an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time, but that value can be a list or other collection that in turn contains multiple values.

Using meaningful variable names helps with the readability of program code and understanding of what values are represented by the variables.

Some programming languages provide types to represent data, which are referenced using variables. These types include numbers, Booleans, lists, and strings.

Some values are better suited to representation using one type of data rather than another.

The assignment operator allows a program to change the value represented by a variable.

The value stored in a variable will be the most recent value assigned.

An algorithm is a finite set of instructions that accomplish a specific task.

Beyond visual and textual programming languages, algorithms can be expressed in a variety of ways, such as natural language, diagrams, and pseudocode.

Algorithms executed by programs are implemented using programming languages.

Every algorithm can be constructed using combinations of sequencing, selection, and iteration.

Sequencing is the application of each step of an algorithm in the order in which the code statements are given.

An expression can consist of a value, a variable, an operator, or a procedure call that returns a value.

Expressions are evaluated to produce a single value.

The evaluation of expressions follows a set order of operations defined by the programming language.

Sequential statements execute in the order they appear in the code segment.

Clarity and readability are important considerations when expressing an algorithm in a programming language.

Arithmetic operators are part of most programming languages and include addition, subtraction, multiplication, division, and modulus operators.

The order of operations used in mathematics applies when evaluating expressions. The MOD operator has the same precedence as the * and / operators.

Some values are better suited to representation using one type of data rather than another.

An index is a common method for referencing the elements in a string using natural numbers.

A string is an ordered sequence of characters.

String concatenation joins together two or more strings end-to-end to make a new string.

A substring is part of an existing string.

A list is an ordered sequence of elements.

An element is an individual value in a list that is assigned a unique index.

An index is a common method for referencing the elements in a list using natural numbers.

Data abstractions can be created using lists.

The exam reference sheet provides basic operations on lists, including:

accessing an element by index

assigning a value of an element of a list to a variable

assigning a value to an element of a list

inserting elements at a given index

adding elements to the end of the list

removing elements

determining the length of a list

A Boolean value is either true or false.

The exam reference sheet provides the following relational operators: =, ≠, >, <, ≥, and ≤.

The exam reference sheet provides the logical operators NOT, AND, and OR, which evaluate to a Boolean value.

The operand for a logical operator is either a Boolean expression or a single Boolean value.

Exam reference sheet has a RANDOM method.

Using random number generation in a program means each execution may produce a different result.