WorksheetsWeek 10 - Loops & String Formatters
Total questions: 82
Worksheet time: 53mins
A while loop can be used in which of the following situations?
Repeat a set of statements till a condition remains True.
Repeat a set of statements a finite or an infinite number of times.
Iterate through a string, list, and tuple.
All of the above
What symbol is used in python to assign values to a variable?
equals =
plus +
minus -
asterisk *
Kind of loop used when you know the number of times you want it to repeat
list
for
while
if
Loop that runs till the condition is true
list
while
for
if
In Python, the two types of loops are _____ and _______
while
for
list
if
Choose the correct output of the following code.
for i in range(10,15):
print(i)
10
11
12
13
14
15
10
11
12
13
14
11
12
13
14
15
11
12
13
14
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
A while loop equivalent of the for loop above is
1,2,3,4
When do you know when you come to the end of the loop?
Its states End loop
The command End is given
The indentation stops
Which type of loop iterates until instructed otherwise?
FOR loop
WHILE loop
Which kind of loop would be used?
I need a guessing game program that will let me keep guessing until I get the right answer.
FOR Loop
WHILE Loop
Which kind of loop would be used?
I need a program that will keep letting me add a monthly payment for 12 months.
FOR Loop
WHILE Loop
numbers = [5, 14, 9, 17]
for number in numbers:
if number % 3 == 0:
print(number)
The output will be?
17
9
14
9
17
14
17
Look at the code below and identify which statement below is true:
Starts at 10, goes up to 100, increases by 10
Starts at 10, goes upto 101, increases by 10
Starts at 1, goes up to 100, increases by 1
Starts at 10, goes up to 10, increases by 10
Look at the following code, what will it generate
1,2,3,4,5,6,7,8,9,10,11,12
0,1,2,3,4,5,6,7,8,9,10,11,12
1,2,3,4,5,6,7,8,9,10,11,12,13
0,1,2,3,4,5,6,7,8,9,10,11,12,13
What does the following program display?
1,2,3,4
1,2,3,4,5
counter,counter,counter,counter,counter
0,1,2,3,4,5
In programming, what is iteration?
The repetition of steps within a program
The order in which instructions are carried out
A decision point in a program
Testing a program to make sure it works
WHILE loops are
loops which run an unknown number of times
loops which run for a specific number of times
the same as if statements
not part of programming
FOR loops are
loops which run an unknown number of times
loops which run for a specific number of times
the same as if statements
not part of programming
A condition is
a statement that is either True or False
a string
an integer
a list
Which kind of loop would be used?
I need a revision program that will run through revision questions 4 times.
FOR Loop
WHILE Loop
Which kind of loop would be used?
I need a program that will keep letting me add money to a piggy bank until I get to £100.
FOR Loop
WHILE Loop
Which method can be used to calculate length:
len()
string()
count()
remove()
+ operator represents fruit1="kiwi"
fruit2="strawberry"
print(len(fruit1))
print(len(fruit2))
kiwi and strawberry
4
10
4 10
410
print(LEN("password")) will return...
Option A
Broken Loop
Not Broken Loop
Option C
Broken Loop
Not Broken Loop
what is the name of the variable used in the following code?
counter
for
#
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
The above program prints
Numbers 1 to 10 in reverse order
Numbers 1 to 11 in reverse order
Numbers 1 to 10
Numbers 1 to 11
The code above prints all numbers between 1 and 30 that are
not divisible by 5
divisible by 5
What will be the output of the code below?
x=123.456
print(format(x, ".1f"))
123.5
123.456
123.4
123.45
What will be the output of the code below?
x=0.78
print(format(x, "%"))
78%
78.0%
78.000%
78.000000%
What will be the output of the code below?
x=0.78
print(format(x, ".2%"))
0.78%
78.0%
78.00%
78.000000%
What will be the output of the code above?
Isabel invested 1,280.46 dollars and now it's worth 2,257.63.
Isabel invested 1,280.469 dollars and now it's worth 2,257.631.
Isabel invested 1280.4693 dollars and now it's worth 2257.6314.
Isabel invested 1280.46 dollars and now it's worth 2257.63.
What will be the output of the code below?
x=0.78
print(format(x, "f"))
0.780000
0.78
78
78.00
What will be the output of the code below?
x=0.78
print(format(x, "d"))
0.780000
0.78
78
ValueError
What will be the output of the code above?
According to Alex's new smart watch he jogged 3.516 miles today.
According to Alex's new smart watch, he jogged 3.5159 miles today.
According to Alex's new smart watch, he jogged 3.51589 miles today.
According to Alex's new smart watch, he jogged 3.52 miles today.
What will be the output of the code below?
a="Marshall"
b="Evelyn"
c="Shawn"
print("Today {0} and {1} studied for a driving test".format(b,c))
Today Marshall and Shawn studied for a driving test
Today Evelyn and Shawn studied for a driving test
Today Marshall and Evelyn studied for a driving test
ValueError
What will be the output of the code above?
After college, Pedro's first job paid him 78,900.020 per year.
After college, Pedro's first job paid him 78,900 per year.
After college, Pedro's first job paid him 78,900.00 per year.
After college, Pedro's first job paid him 78,900.20 per year.
Which format specifier should you use for a high precision number that have decimal point values after its integer value.
f
d
%
i
Which format specifier should you use to covert a number with a decimal point value into a percentage?
f
d
%
i
Which format specifier should you use for an integer value.
f
d
%
i
What will be the output of the code below?
x=75208
print(format(x, ",.2f"))
75,208.00
75,208
75208
ValueError
Given the statement below, what are the minimum and maximum valid character index values in myString3?
String myString3 = "No thanks";
0 and 9
0 and 8
1 and 8
1 and 9
what is a string?
any numeric value
any float value
any character value
any special symbol value
For string symbol + means........................
addition
swapp
concatenation
multiplication
fruit1="kiwi"
fruit2="strawberry"
print(len(fruit1))
print(len(fruit2))
kiwi and strawberry
4
10
4 10
410
index of a string begins with
1
0
a
-1
slicing string X="BOnVoyage"
print X[0:5]
BOnVoy
BOnVo
oyage
bonvo
Slicing string
x="BOnvoyage
print(x[4: ])
BOnvo
bonvo
oyage
VOYAGE
a="god help those who help themselves"
"help" in "a"
true
false
wrong out put
error
What does "\t " make?
Goes to next line
Horizontal space between two strings
Give a title
Add a slash
What does symbol % do?
Integer exact division
Percentage
Division
Remainder
// means:
two times division
integer division
exact division with floating number
Put a slash
Which of the following pieces of code defines a list of all the numbers from 4 to 12?
range(4,12)
range(4, 13)
range( 3,12)
range(3, 13)
What is the output to the console for the featured program?
Esteban
Esteban Esteban
teban
steban
What is the output to the console for the featured program?
Angel
ngel
gel
el
What is the output to the console for the featured program?
Tiffany
fany
Tif
Tiff
What is the output to the console for the featured program?
Samantha
mant
anth
ant
What is the output to the console for the featured program?
8
len(name)
4
Samantha
What is the output to the console for the featured program?
8
len(Edua)
7
4
What is the output to the console for the featured program?
False
True
cat
concatenation
What is the output to the console for the featured program?
D
a
v
i
d
David
0
1
2
3
4
5
What is the output to the console for the featured program?
D
a
v
i
d
David
0
1
2
3
4
5
What is the output to the console for the featured program?
False
True
cat
concatenation
Which of the following prints CDE?
What is the output to the console for the featured program?
J
e
r
m
a
v
i
Jermavi
0
1
2
3
m
a
v
i
What is the correct way to concatenate the variable sign (sign = "Happy day!") to produce the following output?
expected output: “Happy Birthday!”
print(sign[:5] + "Birth" + sign[6:])
print(sign[:6] + "Birth" + sign[5:])
print(sign[:6] + "Birth" + sign[:6])
print(sign[:6] + "Birth" + sign[6:])
What is the output to the console for the featured program?
stress
desserts
dessert
stressed
A condition is
a statement that is either True or False
a string
an integer
a list
Which kind of loop would be used?
I need a program that will keep letting me add a monthly payment for 12 months.
FOR Loop
WHILE Loop
Which kind of loop would be used?
I need a guessing game program that will let me keep guessing until I get the right answer.
FOR Loop
WHILE Loop
Which kind of loop would be used?
I need a revision program that will run through revision questions 4 times.
FOR Loop
WHILE Loop
