1/5/25, 4:56 PM zyBooks
1.1 Programming (general)
Computer program basics
Computer programs are abundant in many people's lives today, carr©yiznygBooouktsa0p1p/0lic5/a2ti5o1n6s:5o6n1703798
Amel Omar
smartphones, tablets, and laptops, powering businesses like Amazon and N e t W
f l i Gx ,UhDe2l 7p 8i nv g1 cars drive
and planes fly, and much more.
A computer program consists of instructions executing one at a time. Basic instruction types are:
Input: A program gets data, perhaps from a file, keyboard, touchscreen, network, etc.
Process: A program performs computations on that data, such as adding two values like x + y.
Output: A program puts that data somewhere, such as to a file, screen, network, etc.
Programs use variables to refer to data, like x, y, and z below. The name is due to a variable's value
"varying" as a program assigns a variable like x with new values.
1.1.1: A basic computer
program.
Computer program
Input (keyboard)
x = Get next input x: 2
2 5
y = Get next input y: 5
z=x+y z: 7
Output (screen)
Put z to output 7
Animation content:
©zyBooks 01/05/25 16:56 1703798
Amel Omar
A generic computer program follows: WGUD278v1
x = Get next input
y = Get next input
z=x+y
Put z to output
Input (keyboard) is as follows:
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 1/71
,1/5/25, 4:56 PM zyBooks
25
Output (screen) is as follows:
7
Animation captions:
01/05/25 16 56 1703798
1. A basic computer program's instructions get input, pr a dp t tp t T s p g a st
Amel Omar
assigns x with what is typed on the keyboard input, in this case 2. WGUD278v1
2. The program's next instruction gets the next input, in this case
3. The program then does some processing, in this case assigning 5. z with x + y (so 2 + 5 yields
7).
4. Finally, the program puts z (7) to output, in this case to a screen.
PARTICIPATIO
N ACTIVITY
1.1.2: A basic computer program.
Consider the example above.
1) How many instructions does the
program have?
Check Show answer
2) Suppose a new instruction were
inserted as follows:
...
z=x+y
Add 1 more to z (new instruction)
Put z to output
What would the last instruction
then output to the screen?
©zyBooks 01/05/25 16:56 1703798
Amel Omar
WGUD278v1
Check Show answer
3) Consider the instruction: z = x + y.
If x is 10 and y is 20, then z is
assigned with .
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 2/71
,1/5/25, 4:56 PM zyBooks
Check Show answer
A program is like a ©zyBooks 01/05/25 16:56 1703798
recipe Amel Omar
WGUD278v1
Some people think of a program as being like a cooking recipe. A recipe consists of
instructions that a chef executes, like adding eggs or stirring ingredients. Likewise,
a computer program consists of instructions that a computer executes, like
multiplying
numbers or outputting a number to a screen.
A first programming activity
Below is a simple tool that allows a user to rearrange some pre-written instructions (in no particular
programming language). The tool illustrates how a computer executes each instruction one at a time,
assigning variable m with new values throughout, and outputting ("printing") values to the screen.
1.1.3: A first programming activity.
Execute the program and observe the output. Click and drag the instructions to change
the order of the instructions, and execute the program again. Not required (points are
awarded just for interacting), but can you make the program output a value greater than
500? How
about greater than 1000?
©zyBooks 01/05/25 16:56 1703798
Run program Amel Omar
WGUD278v1
m:
m = 5
put m
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 3/71
, 1/5/25, 4:56 PM zyBooks
m = m * 2
put m
m = m * m
put m
m = m + 15
put m
©zyBooks 01/05/25 16:56 1703798
Amel Omar
PARTICIPATIO
1.1.4: Instructions. WGUD278v1
N ACTIVITY
1) Which instruction completes the
program to compute a triangle's
area? base = Get next input
height = Get next input
Assign x with base * height
Put x to output
Multiply x by 2
Add 2 to x
Multiply x by 1/2.
2) Which instruction completes the
program to compute the average of
three numbers?
x = Get next input
y = Get next input
z = Get next input
Put a to output
a = (x + y + z) /
3 a = (x + y + z)
/2a=x+y+z
©zyBooks 01/05/25 16:56 1703798
Computational thinking Amel Omar
WGUD278v1
Mathematical thinking became increasingly important throughout the industrial age, to enable people
to successfully live and work. In the information age, many people believe computational
thinking, or creating a sequence of instructions to solve a problem, will become increasingly
important for work and everyday life. A sequence of instructions that solves a problem is called an
algorithm.
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 4/71
1.1 Programming (general)
Computer program basics
Computer programs are abundant in many people's lives today, carr©yiznygBooouktsa0p1p/0lic5/a2ti5o1n6s:5o6n1703798
Amel Omar
smartphones, tablets, and laptops, powering businesses like Amazon and N e t W
f l i Gx ,UhDe2l 7p 8i nv g1 cars drive
and planes fly, and much more.
A computer program consists of instructions executing one at a time. Basic instruction types are:
Input: A program gets data, perhaps from a file, keyboard, touchscreen, network, etc.
Process: A program performs computations on that data, such as adding two values like x + y.
Output: A program puts that data somewhere, such as to a file, screen, network, etc.
Programs use variables to refer to data, like x, y, and z below. The name is due to a variable's value
"varying" as a program assigns a variable like x with new values.
1.1.1: A basic computer
program.
Computer program
Input (keyboard)
x = Get next input x: 2
2 5
y = Get next input y: 5
z=x+y z: 7
Output (screen)
Put z to output 7
Animation content:
©zyBooks 01/05/25 16:56 1703798
Amel Omar
A generic computer program follows: WGUD278v1
x = Get next input
y = Get next input
z=x+y
Put z to output
Input (keyboard) is as follows:
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 1/71
,1/5/25, 4:56 PM zyBooks
25
Output (screen) is as follows:
7
Animation captions:
01/05/25 16 56 1703798
1. A basic computer program's instructions get input, pr a dp t tp t T s p g a st
Amel Omar
assigns x with what is typed on the keyboard input, in this case 2. WGUD278v1
2. The program's next instruction gets the next input, in this case
3. The program then does some processing, in this case assigning 5. z with x + y (so 2 + 5 yields
7).
4. Finally, the program puts z (7) to output, in this case to a screen.
PARTICIPATIO
N ACTIVITY
1.1.2: A basic computer program.
Consider the example above.
1) How many instructions does the
program have?
Check Show answer
2) Suppose a new instruction were
inserted as follows:
...
z=x+y
Add 1 more to z (new instruction)
Put z to output
What would the last instruction
then output to the screen?
©zyBooks 01/05/25 16:56 1703798
Amel Omar
WGUD278v1
Check Show answer
3) Consider the instruction: z = x + y.
If x is 10 and y is 20, then z is
assigned with .
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 2/71
,1/5/25, 4:56 PM zyBooks
Check Show answer
A program is like a ©zyBooks 01/05/25 16:56 1703798
recipe Amel Omar
WGUD278v1
Some people think of a program as being like a cooking recipe. A recipe consists of
instructions that a chef executes, like adding eggs or stirring ingredients. Likewise,
a computer program consists of instructions that a computer executes, like
multiplying
numbers or outputting a number to a screen.
A first programming activity
Below is a simple tool that allows a user to rearrange some pre-written instructions (in no particular
programming language). The tool illustrates how a computer executes each instruction one at a time,
assigning variable m with new values throughout, and outputting ("printing") values to the screen.
1.1.3: A first programming activity.
Execute the program and observe the output. Click and drag the instructions to change
the order of the instructions, and execute the program again. Not required (points are
awarded just for interacting), but can you make the program output a value greater than
500? How
about greater than 1000?
©zyBooks 01/05/25 16:56 1703798
Run program Amel Omar
WGUD278v1
m:
m = 5
put m
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 3/71
, 1/5/25, 4:56 PM zyBooks
m = m * 2
put m
m = m * m
put m
m = m + 15
put m
©zyBooks 01/05/25 16:56 1703798
Amel Omar
PARTICIPATIO
1.1.4: Instructions. WGUD278v1
N ACTIVITY
1) Which instruction completes the
program to compute a triangle's
area? base = Get next input
height = Get next input
Assign x with base * height
Put x to output
Multiply x by 2
Add 2 to x
Multiply x by 1/2.
2) Which instruction completes the
program to compute the average of
three numbers?
x = Get next input
y = Get next input
z = Get next input
Put a to output
a = (x + y + z) /
3 a = (x + y + z)
/2a=x+y+z
©zyBooks 01/05/25 16:56 1703798
Computational thinking Amel Omar
WGUD278v1
Mathematical thinking became increasingly important throughout the industrial age, to enable people
to successfully live and work. In the information age, many people believe computational
thinking, or creating a sequence of instructions to solve a problem, will become increasingly
important for work and everyday life. A sequence of instructions that solves a problem is called an
algorithm.
https://learn.zybooks.com/zybook/WGUD278v1/chapter/1/print 4/71