wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Y11 Programming Basics Pt1 Homework

Total questions: 9

Worksheet time: 3hrs 43mins

Name
Class
Date
1-3.

The three basic programming constructs

Programs are designed using common building blocks. These building blocks, known as programming constructs, form the basis for all programs.

There are three basic building blocks to consider:

  • sequence

  • selection

  • iteration

Sequence is the order in which instructions occur and are processed. Selection determines which path a program takes when it is running. Iteration is the repeated execution of a section of code when a program is running.

There are two types of iteration:

  • count-controlled iteration

  • condition-controlled iteration

All programs use one or more of these constructs. The longer and more complex the program, the more these constructs will be used repeatedly.

1.

What does selection determine in a program?

a)

The output of the program

b)

The speed of the program

c)

The memory usage of the program

d)

The path the program takes when running

2.

What are the three basic building blocks to consider in programming?

a)

Sequence, selection, and iteration

b)

Variables, functions, and objects

c)

Input, output, and processing

d)

Loops, conditionals, and arrays

3.

What is iteration?

a)

The repeated execution of a section of code when a program is running.

b)

The process of compiling a program.

c)

The act of debugging a program.

d)

The method of organizing code into functions.

4-8.

Programs usually use data in some shape or form. Data in programs is usually referred to as values.

Variables

A variable is a named memory address that holds a value. The value held in a variable can (and usually does) change as the program is running.

A variable's name is known as an identifier. The identifier given to a variable usually follows certain rules:

  • It can contain letters and numbers but must start with a letter.

  • It must contain at least one letter (at the start of the name).

  • It must not contain special characters such as !@£$%&* or punctuation characters. However, an underscore can be used. Spaces are not allowed.

  • It should contain lowercase letters. However, uppercase letters can be used if a variable name comprises more than one word joined together.

  • The name should be meaningful - it should represent the value it is holding.

Variables make it easy for a programmer to use memory locations. The computer keeps track of which memory location the variable refers to. All the programmer has to do is remember the identifier the variable was given.

Declaration and assignment

Programming languages require a variable to be identified before a value is assigned to it. This is known as declaring a variable:

score as integer - this would declare a variable called score which will hold integers.

Giving a variable a value is known as assignment. A variable must be assigned a value before it can be used. For example:

Score = 0 - this would assign the value 0 to the variable score.

Some programming languages, such as Python, enable variables to be declared and assigned a value in the same line of code.

Constants

A constant allows a value to be assigned a name. Unlike a variable, the value assigned to a constant cannot be changed whilst the programming in running.

Constants are useful because they are declared and assigned once, but can be referred to over and over again throughout the program. They are used for values that are unlikely to change, for example:

Pi - const PI = 3.142

Constants follow the same naming conventions as variables, except that they are usually in uppercase.

4.

What are the rules for identifying variables in programming?

4 lines
5.

What are variables in programming and what do they hold?

4 lines
6.

What is the purpose of constants in programming and how do they differ from variables?

4 lines
7.

What are the naming conventions for constants in programming?

4 lines
8.

How do variables make it easy for programmers to use memory locations?

4 lines
9-13.

Sequence

Sequence is the first programming construct. In programming, statements are executed one after another. Sequence is the order in which the statements are executed.

The sequence of a program is extremely important as carrying out instructions in the wrong order leads to a program performing incorrectly.

In this pseudocode program designed to find the average of two whole numbers, the instructions are in the wrong sequence:

total = 0 average = number1/number2

number1 = int(input("Enter the first number: “))

number2 = int(input("Enter the second number: "))

print("The average is ", average)

Running this program would result in an error, because it tries to calculate the average before it knows the values of the numbers.

This version has the instructions in the correct sequence:

total = 0

number1 = int(input("Enter the first number: “))

number2 = int(input("Enter the second number: "))

average = number1/number2

print("The average is ", average)

Having instructions in the wrong order is one of the simplest, yet most common, programming errors. It occurs no matter which programming language is used.

9.

What is one of the most common programming errors?

a)

Syntax errors

b)

Logical errors

c)

Having instructions in the wrong order

d)

Using incorrect variable names

10.

Why is the sequence of a program important?

a)

To ensure the program performs correctly

b)

To make the program more efficient

c)

To simplify the coding process

d)

To enhance the program's visual appearance

11.

Why is sequence important in programming?

a)

To make the program function properly

b)

To make the program look neat

c)

To make the program run faster

d)

To make the program more colorful

12.

What can happen if a program is run with instructions in the wrong sequence?

a)

The program will run without any issues

b)

The program will produce incorrect results

c)

The program will terminate immediately

d)

The program will prompt the user for correct instructions

13.

What is the first programming construct?

a)

Sequence

b)

Loop

c)

Conditional

d)

Function

14-17.

Sequence

Sequence is the first programming construct. In programming, statements are executed one after another. Sequence is the order in which the statements are executed.

The sequence of a program is extremely important as carrying out instructions in the wrong order leads to a program performing incorrectly.

In this pseudocode program designed to find the average of two whole numbers, the instructions are in the wrong sequence:

total = 0

average = number1/number2

number1 = int(input("Enter the first number: “))

number2 = int(input("Enter the second number: "))

print("The average is ", average)

Running this program would result in an error, because it tries to calculate the average before it knows the values of the numbers.

This version has the instructions in the correct sequence:

Having instructions in the wrong order is one of the simplest, yet most common, programming errors. It occurs no matter which programming language is used.

14.

What is one of the most common programming errors?

a)

Using the wrong variable name

b)

Forgetting to close parentheses

c)

Having instructions in the wrong order

d)

Not using proper indentation

15.

What is the first programming construct?

a)

Sequence

b)

Loop

c)

Conditional

d)

Function

16.

What is sequence?

a)

The order in which statements are executed

b)

A type of data structure

c)

A mathematical concept

d)

A programming language

17.

What happens to statements in programming?

a)

They are executed simultaneously

b)

They are executed randomly

c)

They are executed one after another

d)

They are executed in a loop

18-21.

Selection

Selection is the second programming construct. In programming, there are occasions when a decision needs to be made. Selection is the process of making a decision. The result of the decision decides which path the program will take next.

For example, a program could tell a user whether they are old enough to learn how to drive a car. If the user's age meets the required driving age, the program would follow one path and execute one set of instructions. Otherwise, it would follow a different path and execute a different set of instructions.

Selection works by testing a condition. The test gives a Boolean result – TRUE or FALSE. If the result is TRUE, the program follows one path - otherwise it follows another.

In programming, selection is implemented using if then else statements:

age = int(input("How old are you? ") if age > 16 then print("You are old enough to drive a car!") else print("Come back when you are older!") endif

In the above pseudocode program, the path the program takes depends on the condition. A variable, in this case age, is used to test the condition.

If the value age is greater than 16, the result of the tested condition is TRUE and the program follows the first path, which follows the statement then. This path informs the user that they are old enough to drive.

If the value of age is less than 16, the result is FALSE and the program follows the second path, which follows the statement else. This path informs the user that they are not yet old enough to drive.

The statement endif ends the selection.

18.

How does selection work in programming?

a)

By testing a condition and giving a Boolean result

b)

By executing a set of statements repeatedly until a certain condition is met

c)

By organizing data in a specific order

d)

By performing mathematical calculations

19.

What statement ends the selection in programming?

a)

endif

b)

if

c)

else

d)

while

20.

What does the result of the decision determine in programming?

a)

The path the program will take next

b)

The title of the passage

c)

The JSON object mentioned in the JSON Schema

d)

The summary of selection in programming

21.

What is selection in programming?

a)

The process of debugging code

b)

The process of making a decision in programming

c)

The process of optimizing code

d)

The process of writing code

22.

Count-controlled iteration

Iteration is the third programming construct. There are times when a program needs to repeat certain steps until told otherwise, or until a condition has been met. This process is known as iteration.

Iteration is also often referred to as looping, since the program ‘loops’ back to an earlier line of code. Sections of codes that are iterated are called loops.

Iteration enables programmers to greatly simplify a program. Instead of writing out the same lines of code again and again, a programmer can write a section of code once, and ask the program to execute it again and again until no longer needed.

This program would print a message out six times:

print(“Coding is cool”)

print(“Coding is cool”)

print(“Coding is cool”)

print(“Coding is cool”)

print(“Coding is cool”)

print(“Coding is cool”)

Count-controlled iteration repeatedly executes a section of code a fixed number of predetermined times. It uses the statements for and next to determine what code is repeatedly executed and how many times. This program would also print out a message six times:

for count = 1 to 6

print(“Coding is cool”)

next count

The first line of the program determines how many times the code is to be iterated. It uses a variable, in this case count, known as the condition variable, to keep track of how many times the code has been repeated so far. The variable is given a starting value (in this case one) and an end value (in this case six).

Every time the code is iterated, the value of count increases by one. At the end of the iteration, the value of count is tested to see if it matches the end value. If the result is FALSE, the code loops back to the start of the iteration and runs again. If it is TRUE, the iteration ends and the program continues with the next line of code.

The condition variable used to initialise a for next loop can be used within the loop itself. This program uses a loop’s condition variable to print the 10 times table:

for count = 1 to 10 print(count * 10) next count

22.

What are the positives of using a Count Controlled Loop?

4 lines
23-27.

Condition-controlled iteration

Condition-controlled iteration repeatedly executes a section of code until a condition is met - or no longer met. There are two types of condition-controlled iteration:

  • while loops - uses the statements while and endwhile

  • repeat loops - uses the statements repeat and until

While condition-controlled loops

While loops test the condition at the beginning of the loop. If the condition is met, the code within the loop is executed before the program loops back to test the condition again. This program would print out a message six times:

count = 0 while count < 6 print(“Coding is cool”) count = count + 1 endwhile

The while statement defines the start of the loop. The endwhile statement declares the end of the loop. A variable, in this case count, is used for the condition. The while statement also tests the condition, in this case to see if the value of count is less than six. If the result is TRUE, the code within the loop is executed, then the program loops back to the condition, which is tested again.

The iteration continues until the condition test result is FALSE, at which point the loop ends and the program executes the next line of code in sequence after the loop.

Because the condition is tested at the start of the loop, it is possible for the code within it to never actually be executed. Consider this program:

count = 6 while count < 6 print(“Coding is cool”) count = count + 1 endwhile

The first time the condition is tested, the result will be FALSE as the value of count is not less than six. Because of this, none of the code within the loop will be executed and the program will move onto the next line of code in sequence after the loop.

Repeat condition-controlled loops

Repeat loops function in the same way as while loops, with one major difference - the condition is tested at the end of the loop:

count = 0 repeat print(“Coding is cool”) count = count + 1 until count = 10

The repeat statement defines the start of the loop. The until statement tests the condition. Because the condition is tested at the end, the code within the loop is always executed at least once, even if the result of the test is FALSE

23.

What is the major difference between repeat loops and while loops?

a)

The condition is tested at the beginning of the loop for repeat loops.

b)

The condition is tested at the end of the loop for repeat loops.

c)

Repeat loops do not have a condition.

d)

Repeat loops have a different syntax than while loops.

24.

What is the purpose of testing the condition at the beginning of a while loop?

a)

To determine if the loop should be executed at all

b)

To determine if the loop should continue executing

c)

To determine if the loop has reached its termination condition

d)

To determine if the loop should skip to the next iteration

25.

What is the purpose of condition-controlled iteration?

a)

To execute a section of code repeatedly until a condition is met

b)

To execute a section of code repeatedly until a condition is no longer met

c)

To execute a section of code only once

d)

To execute a section of code based on a random condition

26.

What happens if the condition in a while loop is not met at the start of the loop?

a)

The code within the loop will execute at least once

b)

The code within the loop will execute indefinitely

c)

The loop will terminate immediately

d)

The loop will skip to the next iteration

27.

In condition-controlled iteration, is the code within a repeat loop always executed at least once, even if the condition is initially false?

a)

Yes

b)

No

c)

It depends on the programming language

d)

It depends on the specific implementation

28-32.

Operators

An operator is a character, or characters, that determine what action is to be performed or considered.

There are three types of operator that programmers use:

  • mathematical operators

  • comparison operators

  • logical operators

These operators are common to most high level programming languages.

Mathematical operators

Computers are designed to carry out calculations. Mathematical operators allow arithmetic to be performed on values.

Mathematical operation

Addition+x = x + 5

Subtraction-x = x - 5

Multiplication*x = x * 5

Division/x = x / 5

Integer DivisionDIVx = x DIV 5

Remainder MODx = x MOD 5

Comparison operators

Comparison operators allow for assignment and for comparisons to be made. They are used in condition testing.

Comparison operator

Equivalence= or ==if x = 5 or if x == 5

Less than<if x < 5

Less than or equal to<=if x <= 5

Greater than>if x > 5

Greater than or equal to>=if x >= 5

Does not equal<> or !=If x <> 5 or if x != 5

Logical operators

Logical operators are used to combine logical operators to give more complex decisions.

Logical Operator

Example And AND if x > 0 AND x < 10

Or ORif topic == "Computing" OR topic == "Computer Science"

Not NOTwhile NOT x

28.

What are logical operators used for?

a)

Combining logical operators to give more complex decisions

b)

Performing mathematical calculations

c)

Manipulating strings

d)

Creating loops

29.

What are operators?

a)

Characters that determine what action is to be performed or considered

b)

Characters that determine the color of the text

c)

Characters that determine the font size

d)

Characters that determine the background color

30.

What is the purpose of comparison operators in programming?

a)

To allow for assignment and comparisons to be made

b)

To perform mathematical operations

c)

To create loops in code

d)

To print output to the console

31.

What do mathematical operators allow to be performed on values?

a)

Comparison operations

b)

Logical operations

c)

Arithmetic operations

d)

String operations

32.

What are the three types of operators?

a)

Mathematical operators, comparison operators, and logical operators

b)

Arithmetic operators, relational operators, and bitwise operators

c)

Unary operators, assignment operators, and ternary operators

d)

Arithmetic operators, logical operators, and bitwise operators

33.

Why is "selection" so important for programming computers?

4 lines