# Computer Programming/Variables

This lesson introduces variables, constants, data types, expressions, statements, and order of operations.

## Contents

## Objectives and Skills[edit]

Objectives and skills for this lesson include:

- Understand variables and constants.
- Use integer, floating-point, and string data types appropriately.
- Use expressions and statements to assign values to variables.
- Understand the order of operations for arithmetic and logical operators.

## Readings[edit]

- Wikipedia: Variable (computer science)
- Wikipedia: Constant (computer programming)
- Wikipedia: Data type
- Wikipedia: Expression (computer science)
- Wikipedia: Statement (computer science)
- Wikipedia: Assignment (computer science)
- Wikipedia: Order of operations
- Wikipedia: Input/output
- Wikipedia: Self-documenting code

## Multimedia[edit]

- YouTube: Elements of High-Quality Programs
- YouTube: Programming/Scripting Concepts Explained (Variables, Arrays, Strings, & Length)
- YouTube: Programming For Beginners - Variables
- YouTube: Programming For Beginners - Data Types
- YouTube: Introduction to Programs Data Types and Variables
- YouTube: Introduction to Programming - Basics
- YouTube: Declaring and using variables and constants
- YouTube: Performing arithmetic operations
- YouTube: Introduction to order of operations
- YouTube: Python3 Input & Output

## Examples[edit]

## Activities[edit]

Complete the following activities using a flowchart tool, pseudocode, or your selected programming language.

- Review MathsIsFun: Order of Operations. Create a program that demonstrates the order of operations. Include parentheses, exponents, multiplication, division, addition, and subtraction in your program.
- Review Wikipedia: Data type. Create a program that demonstrates integer, floating point, and character or string data, and demonstrate converting between data types. For example, user input is always a string, but adding string values of "1" + "1" is typically "11", whereas, adding numeric values of 1 + 1 is 2.
- Create a program to prompt the user for hours and rate per hour and then compute gross pay (hours * rate).
^{[1]} - Create a program that asks the user how old they are in years, and then calculate and display their approximate age in months, days, hours, and seconds.
- Review MathsIsFun: US Standard Lengths. Create a program that asks the user for a distance in miles, and then calculate and display the distance in yards, feet, and inches, or ask the user for a distance in miles, and then calculate and display the distance in kilometers, meters, and centimeters.
- Review MathsIsFun: Area of Plane Shapes. Create a program that asks the user for the dimensions of different shapes and then calculate and display the area of the shapes.
- Review Wikipedia: Zeller's congruence. Create a program that asks the user for their birthday (year, month, and day) and then calculate and display the day of the week on which they were born.

## Lesson Summary[edit]

## Key Terms[edit]

- assignment
- Sets the value saved in the storage location denoted by a given variable name.
^{[2]} - Boolean
- A data type having two values, typically denoted true and false.
^{[3]} - constant
- A value that cannot be altered by the program during normal execution.
^{[4]} - data type
- A classification of data which tells the compiler or interpreter how the programmer intends to use the data.
^{[5]} - declaration
- A language construct that specifies the properties of a given identifier.
^{[6]} - expression
- A combination of one or more explicit values, constants, variables, operators, and functions that a programming language interprets and computes to produce another value.
^{[7]} - floating point
- The formulaic representation that approximates a real number to a fixed amount of significant digits.
^{[8]} - integer
- A number that can be written without a fractional component.
^{[9]} - modulus
- The remainder after division of one number by another.
^{[10]} - operator
- A programming language construct that performs a calculation from zero or more input values to an output value.
^{[11]} - order of operations
- A collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.
^{[12]} - real number
- a value that represents a quantity along a line, including integers, fractions, and irrational numbers.
^{[13]} - statement
- The smallest standalone element of an imperative programming language that expresses some action to be carried out.
^{[14]} - string
- A sequence of characters, either as a literal constant or as some kind of variable.
^{[15]} - variable
- A storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity of information referred to as a value.
^{[16]}

## Assessments[edit]

## See Also[edit]

- Introduction to Programming/Organization part 1
- Introduction to Programming/Variables
- Introduction to Programming/Variables part 2
- Introduction to Programming/Variables part 3
- Programming Logic/Variables

## References[edit]

- ↑ PythonLearn: Variables, expressions, and statements
- ↑ Wikipedia: Assignment (computer science)
- ↑ Wikipedia: Boolean data type
- ↑ Wikipedia: Constant (computer programming)
- ↑ Wikipedia: Data type
- ↑ Wikipedia: Declaration (computer programming)
- ↑ Wikipedia: Expression (computer science)
- ↑ Wikipedia: Floating point
- ↑ Wikipedia: Integer
- ↑ Wikipedia: Modulo operation
- ↑ Wikipedia: Operation (mathematics)
- ↑ Wikipedia: Order of operations
- ↑ Wikipedia: Real number
- ↑ Wikipedia: Statement (computer science)
- ↑ Wikipedia: String (computer science)
- ↑ Wikipedia: Variable (computer science)