WorksheetsProgramming Principles
Total questions: 71
Worksheet time: 36mins
What can be used within programs and functions to organize different types of data in a computer program?
Constants and variables
Functions and arrays
Loops and conditions
Operators and expressions
What is a variable in the context of computer programming?
A fixed memory location
A set of instructions
A named memory location where data can change
A data type
How do we assign a value to a variable in a computer program?
Using a comparison operator
Using an assignment operator
Using an arithmetic operator
Using a logical operator
Which of the following is an example of changing the value of a variable during the running of a program?
age = age + 1
age == age + 1
age + age = 1
age = age
What is a constant in programming?
A variable that can change during the execution of a program.
A named location in memory that contains a value that does not change during the execution of a program.
A function that performs a specific task.
A data type that allows for different values over time.
When writing code, how are constants typically identified?
By using lower case letters.
By using a special symbol at the beginning.
By using upper case letters.
By using italics.
What is an array?
A single value that can store multiple data types.
A set of values of different data types stored under one identifier.
A set of values of the same data type stored under one identifier.
A function that stores multiple values.
What is the size and upper bound index of the array 'studentScores' as declared in the image?
SIZE = 6, UB = 5
SIZE = 7, LB = 0, UB = 6
SIZE = 8, UB = 7
SIZE = 7, LB = 1, UB = 7
How do you add a single value to an array?
By calling a function with the array name and value.
By assigning a value to a specific index of the array.
By using a special array method.
By redeclaring the array with the new value.
What will be the value of 'name1' after executing the code 'String name1 = studentNames[2];'?
Charlie
Oran
Jason
Jimmy
What will be the value of 'score1' after executing the code 'Int score1 = studentScores[0];'?
12
34
56
78
What command is used to get input from a user in a computer program?
print command
Convert.ToInt32
input command
Console.WriteLine
What is the purpose of the Convert.ToInt32(Console.ReadLine()) statement in the example code?
To print a message to the console
To read a line of text from the console
To convert a string to an integer
To declare a variable
Which command is used to output information from a computer program?
Convert.ToDouble
Console.ReadLine
input command
print command
What data type is used by default when reading input from the console using Console.ReadLine()?
int
double
string
DateTime
Which method would you use to convert a string to a double?
Convert.ToInt32
Convert.ToDateTime
Convert.ToDouble
Console.ReadLine
What can programming languages perform on the numbers stored in variables, constants, and arrays?
Mathematical operations
Text formatting
Image processing
Sound manipulation
What are operands in mathematical operations?
The symbols that define the type of operation
The values the operator works on
The result of the operation
The programming language used
Which of the following is NOT a computation represented by operators?
Addition
Multiplication
Subtraction
Spell checking
What is the function of operators in mathematical operations?
To store values in variables
To carry out a mathematical function based on the operator
To compare two values
To define the size of an array
Refer to the diagram below. What does the number 7 represent in the given example?
An operator
An operand
The result of the operation
A variable
Which operator is used in programming to perform addition?
A) /
B) +
C) *
D) MOD
What does the modulus operator MOD return?
A) The quotient of the division
B) The sum of two numbers
C) The remainder of the division
D) The product of two numbers
How is integer division represented in Python?
A) %
B) //
C) /
D) DIV
What is the result of the exponentiation operation 2 ^ 4?
A) 8
B) 16
C) 32
D) 64
What is the result of the Boolean operation NOT applied to False?
True
False
1
0
Which Boolean operator requires both operands to be True for the result to be True?
AND
OR
NOT
==
What is the result of the operation 3 < 6?
True
False
1
0
According to the rules of BODMAS, which of the following operations is evaluated first?
Brackets
Division
Addition
Subtraction
What does the operator '==' signify in Boolean operations?
Is greater than
Is less than
Is equal to
Is not equal to
What does the operator '>=' signify in Boolean operations?
Is less than
Is less than or equal to
Is greater than
Is greater than or equal to
What does 'sequence' mean in the context of program flow?
Repeating a set of instructions multiple times
Executing each instruction once, in the order it is given
Executing instructions in a random order
Ignoring the order of instructions and executing them simultaneously
What will be the output of the following code snippet? name = input("What is your name?\n") print("Hello", name)
What is your name?: Hello Mike
Hello Mike
Mike Hello
What is your name?: Mike Hello
What is the purpose of using conditional statements in a program?
To execute everything in a sequence without any selection
To select which set of instructions to execute based on certain conditions
To repeat a set of instructions multiple times
To stop the program immediately
What will be printed if the name entered is "Mike"?
Access Denied - Wrong Password
Hello Mike
Access Granted
Nothing will be printed
What will be printed if the password entered is "password"?
Access Denied - Wrong Password
Hello Mike
Access Granted
Nothing will be printed
What will be printed if the password entered is not "password"?
Access Denied - Wrong Password
Hello Mike
Access Granted
Nothing will be printed
What will the system output if the user enters the password 'password' correctly?
Access Granted
Access Denied - Wrong Password
Hello Mike
Please enter password: password
What will the system output if the user enters the password 'mike' incorrectly?
Access Granted
Access Denied - Wrong Password
Hello Mike
Please enter password: mike
What will be the output if the age input is 15 in the given IF statement example?
You are a child
You are a teenager
You are an adult
No output
Which of the following age inputs will result in the output "You are an adult" according to the given IF statement example?
10
13
20
8
What is the correct sequence of conditional statements used in the example?
IF > ELSE IF > ELSE
IF > ELSE > ELSE IF
ELSE IF > IF > ELSE
ELSE > IF > ELSE IF
What is iteration in the context of computer programming?
The process of fixing errors in the code
The repetition of a set of instructions
The act of incrementing variable values
The process of compiling the program
Which type of loop is often referred to as count controlled loop?
WHILE loop
DO-WHILE loop
FOR loop
REPEAT-UNTIL loop
What type of loop is a WHILE loop considered as?
Count controlled loop
Condition controlled loop
Infinite loop
Recursive loop
Based on the example provided, what will be the output of the FOR loop?
It will print "Number" followed by numbers 1 to 5
It will print "Number" followed by numbers 0 to 4
It will print "Number" followed by numbers 0 to 5
It will print "Number" followed by numbers 1 to 6
What will be the output of the following code snippet?
0 1 2 3 4 5
1 2 3 4 5 6
0 1 2 3 4
Error message
What is an array in programming?
A function that performs a specific task.
A set of values of the same data type stored under one identifier.
A single value that can change during program execution.
A conditional statement that directs the flow of execution.
What does it mean to declare an array or variable in a program?
To assign a value to it.
To use it in a function.
To create it and specify its type.
To update its value.
How are elements in an array accessed?
Using a loop.
Using the element's name.
Using the index.
Using a conditional statement.
If an array has 10 elements, what is the index of the last element?
10
9
1
0
What is the result of accessing the element at index 2 in the string 'walter'?
w
a
l
t
What symbol is used to concatenate strings in the provided example?
*
+
&
%
What will be the output of the following code snippet? fname = 'walter' sname = 'white' name = fname + ' ' + sname
walterwhite
walter white
walterwhite
walter white
What does the 'Contains' keyword return when searching for a character in a string?
The index of the character
The number of times the character appears
True/False if the character is found or not
The character itself
What would the method call name.Contains("a") return for the string name = "Deighan"?
True
False
Error
None of the above
What would the method call name.Contains("#") return for the string name = "Deighan"?
True
False
Error
None of the above
What does the method call name.SubString(0,1) return for the string name = "Deighan"?
D
De
e
Deighan
What does the method call name.SubString(3,3) return when name is "Deighan"?
A) "Dei"
B) "igh"
C) "gah"
D) "han"
What keyword is used to split strings in the given example?
split()
divide()
separate()
break()
What symbol is used as a delimiter to split the string in the first example?
@
&
%
#
After splitting the string "Mr Deighan@Password" using the split() method, what is the value of details[1]?
Mr Deighan
Password
@Password
Mr
How many elements will the array 'details' contain after splitting the string "Mr Deighan@Password@22@23@19@35"?
2
4
5
6
What is the value of details[4] after splitting the string "Mr Deighan@Password@22@23@19@35"?
22
23
19
35
What does the command .length do in string manipulation?
Converts any data into the string data type
Changes all the characters in the string to upper case
Returns the number of characters in the string, including spaces
Selects a particular part of a string
What is the result of applying the .upper command to the string "name" if the value of name is "walter"?
walter
WALTER
W
ERROR
Which command is used to change all the characters in a string to lower case?
.length
.upper
.lower
str()
How do you select the third character in a string stored in the variable frame?
frame[2]
frame[3]
frame.subString(2, 3)
frame.length
What does the command .subString(x,y) do?
Changes all the characters in the string to upper case
Returns the ASCII number of the character
Converts any data into the string data type
Selects a part of a string starting at index x and selects the next characters, set by y
What is the output of ASC("A")?
65
A
97
119
What does the command Chr() do with a number as its argument?
Returns the ASCII number of the character
Changes all the characters in the string to lower case
Returns the character corresponding to the ASCII number
Selects a particular character in the string
