Programming is writing computer code to create a program, in order to solve a problem. Programs consist of a series of instructions to tell a computer exactly what to do and how to do it.
programSequences of instructions for a computer. are made up of statementThe smallest element of a programming language which expresses an action to be carried out. that the programming language knows and understands.
Just as words are put together to form a sentence, a program puts one or more statements together to form an instructionA single action that can be performed by a computer processor.. Each statement tells the computer to perform a specific task, and the instructions tell a computer what to do.
Statements
Different programming languageA language used by a programmer to write a piece of software. use different statements. A few of these are listed in this table:
Statement
Purpose
print
Output a message on the screen
input
Get data from the user
if…else
A decision
while
A loop controlled by a decision
for
A loop controlled by a counter
def
Create a procedure or function
Statement
print
Purpose
Output a message on the screen
Statement
input
Purpose
Get data from the user
Statement
if…else
Purpose
A decision
Statement
while
Purpose
A loop controlled by a decision
Statement
for
Purpose
A loop controlled by a counter
Statement
def
Purpose
Create a procedure or function
Examples
The following sentence asks someone to write a message on a whiteboard:
“Please write the words ‘Hello world!’ on the board.”
This sentence is an instruction, which contains a single statement. The statement is ‘write the words’. In PythonA high-level programming language. (3.x), the equivalent statement is print.
print("Hello world!")
The following Python (3.x) program contains two instructions, each built up from one statement:
if age >= 17
print("You are old enough to drive a car!")