wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Week 10 - Loops & String Formatters

Total questions: 82

Worksheet time: 53mins

Name
Class
Date
1.

A while loop can be used in which of the following situations?

a)

Repeat a set of statements till a condition remains True.

b)

Repeat a set of statements a finite or an infinite number of times.

c)

Iterate through a string, list, and tuple.

d)

All of the above

2.

What symbol is used in python to assign values to a variable?

a)

equals =

b)

plus +

c)

minus -

d)

asterisk *

3.

Kind of loop used when you know the number of times you want it to repeat

a)

list

b)

for

c)

while

d)

if

4.

Loop that runs till the condition is true

a)

list

b)

while

c)

for

d)

if

5.

In Python, the two types of loops are _____ and _______

a)

while

b)

for

c)

list

d)

if

6.

Choose the correct output of the following code.

for i in range(10,15):       

print(i)

a)

10

11

12

13

14

15

b)

10

11

12

13

14

c)

11

12

13

14

15

d)

11

12

13

14

7.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

8.

A while loop equivalent of the for loop above is

a)
b)
c)
d)
9.
a)
b)
c)
d)

1,2,3,4

10.

When do you know when you come to the end of the loop?

a)

Its states End loop

b)

The command End is given

c)

The indentation stops

11.
What type of loop is used when you know how many times you want to repeat something?
a)
A WHILE Loop
b)
An IF function
c)
A FOR Loop
d)
A Variable
12.

Which type of loop iterates until instructed otherwise?

a)

FOR loop

b)

WHILE loop

13.

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.

a)

FOR Loop

b)

WHILE Loop

14.

Which kind of loop would be used?


I need a program that will keep letting me add a monthly payment for 12 months.

a)

FOR Loop

b)

WHILE Loop

15.

numbers = [5, 14, 9, 17]

for number in numbers:

if number % 3 == 0:

print(number)


The output will be?

a)

17

b)

9

c)

14

9

17

d)

14

17

16.

Look at the code below and identify which statement below is true:

a)

Starts at 10, goes up to 100, increases by 10

b)

Starts at 10, goes upto 101, increases by 10

c)

Starts at 1, goes up to 100, increases by 1

d)

Starts at 10, goes up to 10, increases by 10

17.

Look at the following code, what will it generate

a)

1,2,3,4,5,6,7,8,9,10,11,12

b)

0,1,2,3,4,5,6,7,8,9,10,11,12

c)

1,2,3,4,5,6,7,8,9,10,11,12,13

d)

0,1,2,3,4,5,6,7,8,9,10,11,12,13

18.

What does the following program display?

a)

1,2,3,4

b)

1,2,3,4,5

c)

counter,counter,counter,counter,counter

d)

0,1,2,3,4,5

19.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

20.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
d)
It ensures the code works correctly
21.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
22.

WHILE loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

23.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

24.

A condition is

a)

a statement that is either True or False

b)

a string

c)

an integer

d)

a list

25.

Which kind of loop would be used?


I need a revision program that will run through revision questions 4 times.

a)

FOR Loop

b)

WHILE Loop

26.

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.

a)

FOR Loop

b)

WHILE Loop

27.

Which method can be used to calculate length:

a)

len()

b)

string()

c)

count()

d)

remove()

28.
For strings, the + operator represents 
a)
Concatenation
b)
Addition
c)
Appending
d)
Recantation 
29.

fruit1="kiwi"

fruit2="strawberry"

print(len(fruit1))

print(len(fruit2))

a)

kiwi and strawberry

b)

4

10

c)

4 10

d)

410

30.

print(LEN("password")) will return...

a)
8
b)
7
c)
9
d)
11
31.

Option A

a)

Broken Loop

b)

Not Broken Loop

32.

Option C

a)

Broken Loop

b)

Not Broken Loop

33.

what is the name of the variable used in the following code?

a)

counter

b)

print

c)

for

d)

#

34.
What button do you press to compile (run) your program so that it runs in the shell?
a)
F3
b)
F5
c)
F7
d)
F9
35.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

36.

The above program prints

a)

Numbers 1 to 10 in reverse order

b)

Numbers 1 to 11 in reverse order

c)

Numbers 1 to 10

d)

Numbers 1 to 11

37.

The code above prints all numbers between 1 and 30 that are

a)

not divisible by 5

b)

divisible by 5

38.

What will be the output of the code below?

x=123.456

print(format(x, ".1f"))

a)

123.5

b)

123.456

c)

123.4

d)

123.45

39.

What will be the output of the code below?

x=0.78

print(format(x, "%"))

a)

78%

b)

78.0%

c)

78.000%

d)

78.000000%

40.

What will be the output of the code below?

x=0.78

print(format(x, ".2%"))

a)

0.78%

b)

78.0%

c)

78.00%

d)

78.000000%

41.

What will be the output of the code above?

a)

Isabel invested 1,280.46 dollars and now it's worth 2,257.63.

b)

Isabel invested 1,280.469 dollars and now it's worth 2,257.631.

c)

Isabel invested 1280.4693 dollars and now it's worth 2257.6314.

d)

Isabel invested 1280.46 dollars and now it's worth 2257.63.

42.

What will be the output of the code below?

x=0.78

print(format(x, "f"))

a)

0.780000

b)

0.78

c)

78

d)

78.00

43.

What will be the output of the code below?

x=0.78

print(format(x, "d"))

a)

0.780000

b)

0.78

c)

78

d)

ValueError

44.

What will be the output of the code above?

a)

According to Alex's new smart watch he jogged 3.516 miles today.

b)

According to Alex's new smart watch, he jogged 3.5159 miles today.

c)

According to Alex's new smart watch, he jogged 3.51589 miles today.

d)

According to Alex's new smart watch, he jogged 3.52 miles today.

45.

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))

a)

Today Marshall and Shawn studied for a driving test

b)

Today Evelyn and Shawn studied for a driving test

c)

Today Marshall and Evelyn studied for a driving test

d)

ValueError

46.

What will be the output of the code above?

a)

After college, Pedro's first job paid him 78,900.020 per year.

b)

After college, Pedro's first job paid him 78,900 per year.

c)

After college, Pedro's first job paid him 78,900.00 per year.

d)

After college, Pedro's first job paid him 78,900.20 per year.

47.

Which format specifier should you use for a high precision number that have decimal point values after its integer value.

a)

f

b)

d

c)

%

d)

i

48.

Which format specifier should you use to covert a number with a decimal point value into a percentage?

a)

f

b)

d

c)

%

d)

i

49.

Which format specifier should you use for an integer value.

a)

f

b)

d

c)

%

d)

i

50.

What will be the output of the code below?

x=75208

print(format(x, ",.2f"))

a)

75,208.00

b)

75,208

c)

75208

d)

ValueError

51.

Given the statement below, what are the minimum and maximum valid character index values in myString3?

String myString3 = "No thanks";

a)

0 and 9

b)

0 and 8

c)

1 and 8

d)

1 and 9

52.

what is a string?

a)

any numeric value

b)

any float value

c)

any character value

d)

any special symbol value

53.

For string symbol + means........................

a)

addition

b)

swapp

c)

concatenation

d)

multiplication

54.

fruit1="kiwi"

fruit2="strawberry"

print(len(fruit1))

print(len(fruit2))

a)

kiwi and strawberry

b)

4

10

c)

4 10

d)

410

55.

index of a string begins with

a)

1

b)

0

c)

a

d)

-1

56.

slicing string X="BOnVoyage"

print X[0:5]

a)

BOnVoy

b)

BOnVo

c)

oyage

d)

bonvo

57.

Slicing string

x="BOnvoyage

print(x[4: ])

a)

BOnvo

b)

bonvo

c)

oyage

d)

VOYAGE

58.

a="god help those who help themselves"

"help" in "a"

a)

true

b)

false

c)

wrong out put

d)

error

59.

What does "\t " make?

a)

Goes to next line

b)

Horizontal space between two strings

c)

Give a title

d)

Add a slash

60.

What does symbol % do?

a)

Integer exact division

b)

Percentage

c)

Division

d)

Remainder

61.

// means:

a)

two times division

b)

integer division

c)

exact division with floating number

d)

Put a slash

62.

Which of the following pieces of code defines a list of all the numbers from 4 to 12?

a)

range(4,12)

b)

range(4, 13)

c)

range( 3,12)

d)

range(3, 13)

63.

What is the output to the console for the featured program?

a)

Esteban

b)

Esteban Esteban

c)

teban

d)

steban

64.

What is the output to the console for the featured program?

a)

Angel

b)

ngel

c)

gel

d)

el

65.

What is the output to the console for the featured program?

a)

Tiffany

b)

fany

c)

Tif

d)

Tiff

66.

What is the output to the console for the featured program?

a)

Samantha

b)

mant

c)

anth

d)

ant

67.

What is the output to the console for the featured program?

a)

8

b)

len(name)

c)

4

d)

Samantha

68.

What is the output to the console for the featured program?

a)

8

b)

len(Edua)

c)

7

d)

4

69.

What is the output to the console for the featured program?

a)

False

b)

True

c)

cat

d)

concatenation

70.

What is the output to the console for the featured program?

a)

D

a

v

i

d

b)

David

c)

0

1

2

3

4

d)

5

71.

What is the output to the console for the featured program?

a)

D

a

v

i

d

b)

David

c)

0

1

2

3

4

d)

5

72.

What is the output to the console for the featured program?

a)

False

b)

True

c)

cat

d)

concatenation

73.

Which of the following prints CDE?

a)
b)
c)
d)
74.

What is the output to the console for the featured program?

a)

J

e

r

m

a

v

i

b)

Jermavi

c)

0

1

2

3

d)

m

a

v

i

75.

What is the correct way to concatenate the variable sign (sign = "Happy day!") to produce the following output?

expected output: “Happy Birthday!”

a)

print(sign[:5] + "Birth" + sign[6:])

b)

print(sign[:6] + "Birth" + sign[5:])

c)

print(sign[:6] + "Birth" + sign[:6])

d)

print(sign[:6] + "Birth" + sign[6:])

76.

What is the output to the console for the featured program?

a)

stress

b)

desserts

c)

dessert

d)

stressed

77.

A condition is

a)

a statement that is either True or False

b)

a string

c)

an integer

d)

a list

78.
To repeat until a particular condition is true use
a)
while loop
b)
for loop
c)
if loop
d)
indentation
79.
The condition for a while loop to continue could include which of the following?
a)
While something equals something
b)
While something is greater than something
c)
While something is True
d)
All of these
80.

Which kind of loop would be used?


I need a program that will keep letting me add a monthly payment for 12 months.

a)

FOR Loop

b)

WHILE Loop

81.

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.

a)

FOR Loop

b)

WHILE Loop

82.

Which kind of loop would be used?


I need a revision program that will run through revision questions 4 times.

a)

FOR Loop

b)

WHILE Loop