Basic Programming Quiz
Questions: 16 · 10 minutes
1. A program runs: IF temperature > 30, PRINT “Hot.” If temperature equals 30 and there is no ELSE branch, what is printed?
The number 30
The word “Hot”
No message is printed
The condition automatically causes an error
2. What is a loop primarily used for?
Declaring every variable before a program starts
Choosing a data type based on user input
Repeating a block of instructions under defined conditions
Converting comments into executable instructions
3. In the function definition greet(name), what is name called?
A return value
A Boolean operator
A loop counter
A parameter
4. What does a return statement normally do inside a function?
Restarts the entire program from the beginning
Repeats the function until its input changes
Turns every local variable into a global variable
Ends the function’s current execution and can send a value back to its caller
5. When does the Boolean expression A AND B evaluate to true?
Whenever A is true, regardless of B
Whenever at least one of A or B is true
Only when A and B have different values
Only when both A and B are true
6. A program should allow entry when a person's age is 18 or greater. Which condition expresses that rule?
age is greater than or equal to 18
age is exactly equal to 18
age is strictly greater than 18
age is less than or equal to 18
7. Which data type is most appropriate for a value that can only be true or false?
String
Integer
Boolean
Floating-point number
8. What is the main purpose of an ordinary comment in source code?
To help people understand the code without acting as a normal executable instruction
To make the next instruction repeat
To store text that the program must display
To request input from the user
9. What is an algorithm?
A finite, ordered set of steps for solving a problem
A programming language used only for calculations
A list containing every possible program error
A physical component that executes source code
10. Which situation is most likely to create an unintended infinite loop?
The loop body updates the value used in its condition
The loop processes an empty collection and then stops
The loop condition stays true because the relevant value never changes
The loop condition is false before the first iteration
11. The statement PRINT(""Hello"" is missing its closing parenthesis. What kind of error is this?
A logic error
A syntax error
An input-validation error
A boundary-case error
12. A nonempty list contains several test scores. Which calculation gives its arithmetic mean?
Add the highest and lowest scores only
Add all scores and divide by the number of scores
Multiply all scores by the number of scores
Subtract the lowest score from the highest score
13. Consider this pseudocode: x ← 5, then x ← x + 2. What value does x hold afterward?
5
7
10
52
14. Trace this pseudocode: count ← 0; WHILE count < 3, set count ← count + 1; after the loop, PRINT count. What is printed?
3
2
4
Nothing, because the loop never ends
15. What is the main purpose of a variable in a program?
To translate source code into machine instructions
To store a value that the program can use or change
To repeat every instruction in the program
To detect and repair errors automatically
16. A program accepts users aged 18 or older using the condition age >= 18. Which pair of ages most directly tests the acceptance boundary?
1 and 100
18 and 50
20 and 21
17 and 18