NEW
Font size
WorksheetsProgramming Basics Quiz
Total questions: 38
Worksheet time: 19mins
What is the definition of a variable in programming?
A command used to repeat a block of code.
A keyword used for making decisions.
A named location in memory used to store data that your program can use and manipulate.
A specific function used to output text to the screen.
Which data type in Python is used to store whole numbers (positive or negative)?
Float
String
Boolean
Integer (int)
The Boolean data type is used to represent which type of information?
Decimal numbers / real numbers
Combinations of text, numbers and symbols
Individual characters
Yes/No, On/Off, or logical conditions (True, False)
Why is it important for programs to use variables?
They speed up the program's execution time.
They automatically fix syntax errors.
They store information for the program to use later and make programs dynamic, flexible, readable, and maintainable.
They are required only when accepting user input.
Which data type is appropriate for tracking the value of a treasure chest that could be fractional (e.g., 3.14)?
Integer (int)
Character (char)
Float (float)
String (str)
What is the primary purpose of adding comments to code, typically starting with a hashtag (#)?
The computer uses them to verify the program's efficiency.
The comments are automatically converted into output.
They are used to change the data type of a variable.
To explain what the code does, help teammates understand the program, and make programs easier to maintain.
If a programmer is using 'snake_case' for variable names, which option is correctly following this convention?
CrewName
crew_name
Crew-Name
Crew.Name
What is the term for the process of following code step by step, like a computer would, often using a table to track variable changes?
Debugging
Compiling
Tracing
Iteration
Which standard command is used in Python code to retrieve information entered by the user?
print()
def
input()
range()
In the following code snippet, which part represents variable assignment? energy = 3
energy (The variable name)
3 (The value)
= (The assignment operator)
The entire line is an input statement.
What is the effect of the following Python line? print("Welcome:", crew_name)
It calculates a value and stores it in crew_name.
It asks the user for input.
It displays the text "Welcome:", followed by the value currently stored in the variable crew_name.
It starts a loop.
Which statement is used after an if statement to handle an alternative condition when the initial condition is false?
while
else
for
break
When writing conditional logic, which statement is used to check an additional condition if the preceding if and elif conditions were false?
if True:
break
elif
print()
In Python, when checking if a variable choice is exactly equal to the string "ghost", which syntax is correct?
if choice = "ghost":
if choice == "ghost":
if choice is "ghost":
if choice != "ghost":
What is the programming term for an if statement placed inside another if statement?
Concatenated If
Extended If
Sequential If
Nested If
In a decision structure containing if, elif, and else statements, how many of the associated code blocks will execute?
All of them will execute sequentially.
At least two blocks will execute.
Only the first true condition's block will execute, or the else block if none are true.
Only the if and the else blocks will execute.
What is the main benefit of using loops in programming?
Loops are necessary only for mathematical calculations.
Loops save time, make programs shorter, and reduce errors by repeating actions.
Loops are used exclusively for handling user input.
Loops automatically define new variables.
Which type of loop repeats a block of code for a fixed number of times?
While loop
For loop
Procedure
Conditional loop
What command is used to immediately stop and exit a while loop, even if its condition is still true?
continue
stop
exit
break
If a while loop condition is set using while True:, how can the loop be prevented from running infinitely?
By ensuring the input is always correct.
By using a break command when a certain condition is met.
By changing the while True command to while False.
while True loops automatically stop after 10 iterations.
What is the initial value of the variable i in the first iteration of the following loop? for i in range(1, 6):
0
1
5
6
How are lists typically created and defined in Python code?
Using curly braces {}
Using parentheses ()
Using angle brackets <>
Using square brackets []
If you have a list called weapons containing 5 items, which position number (index) refers to the first item in the list?
1
0 (due to zero indexing)
5
-1
Which term describes accessing a range of items from a list rather than just one item?
Indexing
Iterating
Slicing
Appending
Given the list ships = ["Black Pearl", "Queen Anne's Revenge", "Flying Dutchman"], what is the index number for "Queen Anne's Revenge"?
0
1
2
3
Which built-in list function is used to add a new item to the end of an existing list?
insert()
remove()
len()
append()
Which list function is used to determine the number of items currently stored in the list?
count()
len()
size()
list_length()
What is the main characteristic of a procedure (a type of subroutine)?
It returns a value to the main program.
It is only used for repeating loops.
It performs an action but does not return a value.
It must contain at least one parameter.
In Python, what keyword is used to define a procedure?
proc
define
def
routine
Which of the following is a function often used from an imported library to introduce a time delay in a program's execution?
time.pause()
random.time()
time.delay()
time.sleep()
What Python function, commonly used after importing the random library, allows the program to select and return a random element from a given list or sequence?
random.randint()
random.choice()
random.shuffle()
random.select()
In the code definition def open_door(name):, what is name an example of?
A return value
A local variable
A parameter
A conditional statement
When a program needs to use functions like randint() or sleep(), what must the programmer usually do first?
Declare all variables as global.
Create a class instance.
Use an import statement for the necessary library (e.g., import random).
Write a tracing table.
Which debugging step involves tracking the values of variables as they change during the execution of a loop iteration by iteration?
Using the print() function only at the end.
Using a trace table.
Inserting comments.
Converting variables to Boolean type.
Look at the following code structure. If the initial value of energy is 3, what will happen? energy = 3 while energy < 0: print("A demon drains your life!") energy = energy - 1
The loop will run three times.
The loop will run infinitely.
The loop will run, and energy will continuously decrease.
The condition is immediately false (3 < 0 is false), so the loop body will not execute.
In list slicing, if you use list_name[start:end], which element is excluded from the resulting slice?
The element at the start index.
The element at index 0.
The element at the end index.
The element at the middle index.
What is the expected output of the following list operation? supplies = ["rum", "bread", "gunpowder"] print(supplies.remove("bread"))
['rum', 'gunpowder']
bread
None (The remove() function modifies the list in place and usually returns None in Python)
Error
A programmer wants a loop to count down from 10 to 1, step by step. When using range(start, stop, step), what value should the step parameter be?
1
0
10
A negative step value (e.g., -1)
