wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Review for Python 3 Test - Loops and Strings (CodeCademy)

Total questions: 100

Worksheet time: 58mins

Name
Class
Date
1.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
2.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
3.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
4.

What will be the output?

name = "Dave"

print (name)

a)

Dave

b)

'Dave'

c)

name

d)

(name)

5.
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
a)
True
b)
False
6.
Which statement correctly assigns the string "Tanner" to the variable name?
a)
name  = print( "Tanner")
b)
input("Tanner")
c)
name = "Tanner"
d)
name = input("Tanner")
7.
What will be the output?
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
a)
Good moning 'Dave'
b)
Good morning Dave
c)
Good morning name
d)
Good morning + Dave
8.
What would print (10 + 16) produce?
a)
20
b)
22
c)
24
d)
26
9.
What will the output be from the following code?
print("Hello" + str(2) + "world!")
a)
Hello world! Hello world!
b)
Hello2world!
c)
Hello Hello world! world!
d)
SyntaxError
10.
Code repeated / looped until a condition has been met or a set number of times.
a)
Sequence
b)
Selection
c)
Iteration
d)
Variable
11.

What does the following code do? myAge = int (myAge)

a)

Converts the var (variable) myAge to a string

b)

Converts the var (variable) myAge to a integer

c)

Converts the var (variable) myAge from a integer to a string

d)

Converts the var (variable) myAge to if statement

12.
Tells the interpreter that the code which follows is a function
a)
const
b)
int
c)
def
d)
while
13.
What will the output be from the following code?
print("Hello world!" * 2)
a)
TypeError
b)
Hello world world!
c)
Hello world!Hello world!
d)
Hello world! * 2
14.
Joining elements together to make a string is called what?
a)
Combining
b)
Connecting
c)
Concatenation
d)
Stringing
15.

people = ["John", "Rob", "Bob"]

print (people[1])

what would this result be?

a)
John
b)
Rob
c)
Bob
16.

people = ["John", "Rob", "Bob"]

print (people[-1])

what would this result be?

a)
John
b)
Rob
c)
Bob
17.

people = ["John", "Rob", "Bob"]

print (people[4])

what would this result be?

a)
John
b)
Rob
c)
Bob
d)
Error
18.

Which one will display when this code is run?

a)
b)
c)
d)
19.

If you want to create an empty list called colours in Python, which of the following is correct?

a)

colours = [ ]

b)

colours = ( )

c)

colours = { }

d)

colours = <>

20.
What letter will be printed on the screen after running this code:
a)
e
b)
x
c)
t
d)
Nothing prints
21.
What is the position of the name "Robert" in the following list:
a)
0
b)
1
c)
2
d)
3
22.
What output will this code produce?
a)
4
b)
2
c)
3
d)
5
23.
What output will this code produce?
a)
3
b)
20
c)
25
d)
17
24.
print("12"*3)
What would this print?
a)
36
b)
121212
c)
24
d)
12*3
25.

What is the Python built-in function to converts a number to a string?

a)

str()

b)

int()

c)

parseInt()

d)

convert

26.
The correct way to write a variable in Python?
a)
my_variable = 10
b)
my variable = 10
c)
my_variable is 10
d)
my_variable: 10
27.

Which of these is correct Python conditional statement?

a)

IF answer == "Yes":

b)

if answer == "Yes"

c)

if answer == "Yes":

d)

if answer = "yes":

28.

What is a Count-Controlled loop?

a)

for loop

b)

while loop

29.

A count controlled loop will..

a)

Repeat code until a condition is met

b)

Repeat code a specific amount of times

c)

Repeat code a random amount of times

d)

None of the above

30.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error

31.

Which of these is NOT a loop in python?

a)

for loop

b)

while loop

c)

nested loop

d)

if loop

32.

Which of these operators means EQUAL TO?

a)

'='

b)

'=>'

c)

'<='

d)

'=='

33.

What will be the output of this code?

a)

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

b)

0,2,4,6,8,10

c)

2,4,6,8,10,12

d)

2,4,6,8,10

34.

What does the '#' allow you to do?

a)

Repeat code

b)

Comment on code

c)

Print code

d)

End code

35.

Which of these will allow me to count from 0-20 in steps of 5?

a)

for x in range(0,20):

print(x)

b)

while x = (0,20,5):

print(x)

c)

for x in range(0,21,5):

print(x)

d)

for x in range(0,21,5):

print(y)

36.

If i want to continuously check for a correct answer, what loop would i use?

a)

for loop

b)

while loop

37.

What is the error in this code?

a)

incorrect variable name

b)

incorrect indentation

c)

incorrect speech marks

d)

incorrect loop

38.

A condition controlled loop is...

a)

A while loop

b)

A for loop

39.

x = 5

y = 6

print(x*y)


The code above displays the following:

a)

11

b)

x*y

c)

Syntax Error

d)

30

40.

x = 5

y = 6

print("x*y")


The code above displays the following:

a)

11

b)

x*y

c)

Syntax Error

d)

30

41.

Operators used in python:


divide, multiply, add, subtract

a)

/, *, +, -

b)

div, mul, +, -

c)

\, x, +, -

d)

~, *, +, -

42.

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

43.
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
44.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
45.
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
46.

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

47.

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

48.

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

49.

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

50.

The correct syntax of the len function for string x:

a)

x.len()

b)

len[x]

c)

LEN[]

d)

len(x)

51.

Let x= "python is a high level language", the output of print(len(x[-1])) is

a)

1

b)

31

c)

Error

d)

25

52.

Let x= "Python", the output of

print(x[0])

print(x[1])

print(x[2])

a)

PYT

b)

P

y

t

c)

T

h

o

d)

n

oh

53.

Let x= "Python", the output of

print(x[0])

print(x[-1])

print(x[-2])

a)

P

N

O

b)

p

O

n

c)

t

h

y

d)

P

n

o

54.
What output will this code produce?
a)
1
b)
3
c)
2
d)
4
55.
What output will this code produce?
a)
1
b)
3
c)
i
d)
0
56.

word = "amazing"


For the given string if we run word[2:5] , what would the result be?

a)

mazi

b)

mazin

c)

azi

d)

azin

57.

For strings, the + operator represents

a)

Concatenation

b)

Addition

c)

Appending

d)

Recantation

58.

data = "No Way!" The expression len(data) evaluates to:

a)

7

b)

9

c)

8

d)

6

59.
Used to create exponents
a)
**
b)
"""
c)
%
d)
#
60.
symbol used for modulo
a)
%
b)
&
c)
#
d)
**
61.

Which operator checks if a value is equal to another value?

a)

+

b)

=

c)

==

d)

!=

62.

Which operator checks if a value is not equal to another value?

a)

==

b)

+=

c)

!=

d)

=

63.
If you want more than one option for your code, what do you use (after if)?
a)
elif
b)
else
c)
ifif
64.
What will the following lines of code print?
a)
A
b)
B
C
c)
A
C
d)
Nothing, it will return an error.
65.
What will be printed after running this FOR loop:

for number in range(6):
 
    print(number)
a)
The number 6 
b)
The numbers 0 - 5
c)
The number 5
d)
The numbers 1 - 6
66.
a)
5
4
3
2
1
b)
5  4  3  2  1
c)
4
3
2
1
0
d)
4  3  2  1  0
67.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

68.
What output will this code produce?
a)
Exeter
b)
4
c)
6
d)
city
69.
a)
10  8  6  4  2
b)
10
8
6
4
2
c)
2  4  6  8  10
d)
10  9  8  7  6  5  4  3  2  1
70.
a)
0  5  10
b)
5  10
c)
0  5  10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95  100  105  110  115  120  125  130  135  140......etc
d)
12  7  2
71.
a)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
b)
Hello world!
c)
Hello world!
break              
d)
Error
72.
a)
Hello world!
b)
Error
c)
Hello world!
False
d)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
73.

What is the result of following Program in python3

if(32%2==0):

print("32")

else:

print("2")

a)

2

b)

32

c)

error

74.

What is the result of following Program in python3

for i in range(3,1):

print(i)

a)

3

2

b)

3

2

1

c)

error

d)

2

1

0

75.

What is the result of following Program in python3

for i in range(1,4):

print(i)

if(i==2):

break;

a)

1

b)

1

2

c)

1

2

3

4

d)

error

76.

Terminates the loop statement and transfers execution to the statement immediately following the loop

a)

pass statement

b)

continue statement

c)

break statement

77.

Causes loop to skip the remainder of its body and immediately retest its condition to reiterating

a)

continue statement

b)

break statement

c)

pass statement

78.

break will break out of an iteration

a)

true

b)

false

79.

continue will move to the next iteration

a)

true

b)

false

80.

How long will a loop continue

a)

As long as the condition is true

b)

Forever

81.

What command forces a loop to stop

a)

break

b)

but

c)

broke

d)

breaking

82.
What does the APPEND procedure do in the following code:
a)
Adds Liverpool to the beginning of the list
b)
Replaces Bristol with Liverpool
c)
Replaces Manchester with Liverpool
d)
Adds Liverpool to the end of the list
83.
What output will this code produce?
a)
['France', 'Wales', 'England']
France
b)
['France', 'Wales', 'England']
Wales
c)
France, Wales, England
Wales
d)
France  Wales  England
France
84.

How do you create a variable with the numeric value 5?

a)

x = int(5)

b)

x = 5

c)

Both the other answers are correct

85.

Which method can be used to remove any whitespace from both the beginning and the end of a string?

a)

trim()

b)

ptrim()

c)

strip()

d)

len()

86.

The correct syntax for converting the string x to uppercase is :

a)

X.upper()

b)

upper(x)

c)

x.UPPER[ ]

d)

x.upper()

87.

The correct syntax for converting the string myname to lowercase is :

a)

myNAME.lower[ ]

b)

myname.lower( )

c)

myname.upper( )

d)

myname_lower(12 )

88.

mountain_name = "Mount Kilimanjaro"

print(mountain_name.find("o"))


What prints to the console

a)

0

b)

1

c)

-1

d)

2

89.

fruit = "Strawberry"

print(fruit.replace('r', 'R'))


What prints in the console?

a)

StRawbeRRy

b)

StRawberry

c)

Strawberry

d)

STRAWBERRY

90.

x = "-".join(["Codecademy", "is", "awesome"])

print(x)


what prints in the console?

a)

Codecademy is awesome

b)

Codecademyisawesome

c)

Codecademy-is-awesome

d)

Codecademy.is.awesome

91.

dinosaur = "T-Rex"

print(dinosaur.upper())


What prints to the console?

a)

T-REX

b)

t-rex

c)

T-Rex

92.

text = "Silicon Valley"

print(text.split())


What prints to the console?

a)

['Silicon', 'Valley']

b)

['Silicon Valley']

c)

['Silicon']

d)

['Valley']

93.

text = "Silicon Valley"


print(text.split('i'))


What prints to the console?

a)

['S', 'l', 'con Valley']

b)

['Silicon, 'll']

c)

['l', "ll]

d)

['Silicon', 'Valley']

94.

my_var = "dark knight"

print(my_var.title())


What prints to the console?

a)

Dark Knight

b)

DARK KNIGHT

c)

DARK Knight

d)

dark knight

95.

greeting = "Welcome To Chili's"

print(greeting.lower())


What prints to the console?

a)

welcome to chili's

b)

Welcome to Chili's

c)

WELCOME TO CHILI'S

d)

Welcome to chili's

96.

text1 = ' apples and oranges '

text1.strip()


What prints to the console?

a)

'apples and oranges'

b)

'apples'

c)

'oranges'

d)

' apples and oranges '

97.

text2 = '...+...lemons and limes...-...'

text2.strip('.')


What prints to the console?

a)

'+...lemons and limes...-'

b)

'lemons'

c)

'limes'

d)

'...lemonsandlimes...'

98.

text2 = '...+...lemons and limes...-...'

text2.strip('.+-')


What prints to the console?

a)

'lemons and limes'

b)

'lemons'

c)

'limes'

d)

'...lemons and limes...'

99.

msg1 = 'Fred scored {} out of {} points.'

msg1.format(3, 10)


What prints to the console?

a)

'Fred scored 3 out of 10 points.'

b)

3,10

c)

3,4,5,6,7,8,9

d)

'Fred scored 3,4,5,6,7,8,9,10 points'

100.

colors = ['red', 'yellow', 'green']

print(len(colors))


What prints to the console?

a)

3

b)

3,6,5

c)

14

d)

2