WorksheetsCP M4 Repetition & Loops
Total questions: 15
Worksheet time: 8mins
A (a) is a collection of commands that are given a name.
True or False. Every WHILE loop can be replaced with FOR loop.
True
False
Variable used to end the loop
Loop control variable
count variable
While loops should always be:
output
indented
calculated
input
For a loop to stop, the loop control variable must ________________.
change
be input from the keyboard
be true
change inside the loop
What is wrong with:
x = 1
while (x < 20):
print (x)
There is no x = 0 before the loop
The loop will not stop since the condition is wrong
x should be c
The loop will not stop since x never changes
Why do we use loops?
Because computers can do calculations humans can't.
Because programming is an important skill
Because of efficiency.
Because programs need to make decisions.
Consider the following code:
x = 9
sum = 0
while (x < 19):
x = x + 1
num = int(input("Enter a number: "))
sum = sum + num
print (str(x) + ": " + str(num) + " Total: " + str(sum))
Which of the following is the loop-control variable?
num
sum
x
int
Which of the following is NOT true about while loops?
A way of repeating a code
Use conditions like if statements
Used to create functions
Give us more control over how the program runs
Which of the following is NOT a rule for algorithms?
They produce a result.
They have an order.
They repeat indefinitely.
They have clear instructions.
Information sent to a function is a?
Sum
Loop Control Variable
Range
Parameter
We trace code in order to identify errors and to predict output.
True
False
The process of using random numbers made by computers to test computer models.
Monte Carlo Method
Simulation
Modeling
Algorithm
The process of reading through code to find errors and predict results.
Monte Carlo Method
Tracing Code
Modeling
Simulation
A precise rule (or set of rules) specifying how to solve some problem
Algorithm
Sum
Function
Parameter
