wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python_22

Total questions: 71

Worksheet time: 34mins

Name
Class
Date
1.
Stores a piece of data, and gives it a specific name
a)
variable
b)
whitespace
c)
interpreter
d)
modulus
2.
Returns the remainder from division
a)
modulus
b)
exponents
c)
boolean
d)
variables
3.
Surrounds multi-line comments
a)
"""
b)
**
c)
#
d)
%
4.
A line of text that Python won't try to run as code
a)
comment
b)
modulus
c)
variable
d)
boolean
5.
Symbol used for modulus
a)
%
b)
&
c)
#
d)
**
6.
A data type than can have one of two values: True or False
a)
boolean
b)
variable
c)
modulus
d)
interpreter
7.
Used to make comments
a)
#
b)
%
c)
**
d)
()
8.
The correct way to write a variable in Python?
a)
myVariable = 10
b)
my Variable = 10
c)
myVariable is 10
d)
myVariable: 10
9.
10= 100
Which of the following is used in Python to calculate ten squared?
a)
10 ** 2
b)
10 * 2
c)
10 % 2
d)
10 ** 10
10.
To solve a problem that requires the user to enter 10 numbers would use what type of iteration?
a)
While loop
b)
For loop
c)
Variable
d)
Selection
11.
A data type consisting of numbers, letters and symbols.
a)
String
b)
Integer
c)
Float
d)
Boolean
12.
Code executed based on a condition being true
a)
Sequence
b)
Selection
c)
Iteration
d)
Variable
13.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)
SyntaxError
c)
Hello world
d)
print(Hello world!)
14.
What will the output be from the following code?
print(3+4)
a)
3+4
b)
7
c)
SyntaxError
d)
print(3+4)
15.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
16.
What will the output be from the following code?
print("Hello" + "world!")
a)
Hello world!
b)
Helloworld!
c)
SyntaxError
d)
"Hello" "world!"
17.
Which Python command is used to output information to the screen?
a)
read
b)
output
c)
print
d)
display
18.

Which has integer data type?

a)

Phone number

b)

Zip code

c)

HN

d)

Number of students in the class

19.
what is 8%2
a)
0
b)
16
c)
24
d)
86
20.

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

21.

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

22.
a)
b)
c)
d)

1,2,3,4

23.

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

24.

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

a)

counter

b)

print

c)

for

d)

#

25.

Which of the following is an acceptable variable name?

a)

no-text

b)

8text

c)

no_text

d)

no_text$

26.
What does the print function do in python?
a)
It's a variable.
b)
It can input data.
c)
It displays something like a string or integer
d)
It loops the code.
27.
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
28.

Which of the following are true of Python dictionaries:

a)

Dictionaries can be nested to any depth.

b)

Dictionaries are accessed by key.

c)

All the keys in a dictionary must be of the same type.

d)

Dictionaries are mutable.

e)

A dictionary can contain any object type except another dictionary.

29.

Which of the following is not a valid way to define this dictionary in Python:

a)

d = dict([

('foo', 100),

('bar', 200),

('baz', 300)

])

b)

d = {}

d['foo'] = 100

d['bar'] = 200

d['baz'] = 300

c)

d = dict(foo=100, bar=200, baz=300)

d)

d = {'foo': 100, 'bar': 200, 'baz': 300}

e)

d = { ('foo', 100), ('bar', 200), ('baz', 300) }

30.

Consider this dictionary:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What is the result of this statement:


d['bar':'baz']

a)

It raises an exception

b)

(200, 300)

c)

200 300

d)

[200, 300]

31.

Suppose x is defined as follows:

x = [

'a',

'b',

{

'foo': 1,

'bar':

{

'x' : 10,

'y' : 20,

'z' : 30

},

'baz': 3

},

'c',

'd'

]

What is the expression involving x that accesses the value 30?

a)

x[2]["bar"]["z"]

b)

x[2]["bar"]

c)

x["bar"]["z"]

d)

x[2]["bar"]["z"][3]

32.

Which of the following could be a valid dictionary key:

a)

(3+2j)

b)

('foo', 'bar')

c)

dict(foo=1, bar=2)

d)

'foo'

e)

['foo', 'bar']

33.

You have the following dictionary definition:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What method call will delete the entry whose value is 200?

a)

delete d('bar')

b)

d.pop("bar")

c)

d.remove("bar")

d)

None of the above

34.

Suppose you have a dictionary d1. Which of the following effectively creates a variable d2 which contains a copy of d1:

a)

d2 = dict(d1.items())

b)

d2 = dict(d1.keys())

c)

d2 = {}

d2.update(d1)

d)

d2 = dict(d1.values())

e)

d2 = dict(d1)

35.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}


for key in a_dict:

print(key)

a)

'blue'

'apple'

'dog'

b)

color

fruit

pet

c)

blue

apple

dog

d)

'color'

'fruit'

'pet'

36.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

37.

Consider the following statement:


If you just need to work with the keys of a dictionary, then you can use .keys(), which is a method that returns a new view object containing the dictionary’s keys.


Is this statement True or False?

a)

False

b)

True

38.

One of the following functions is not used with Python String

a)

Split

b)

Remove

c)

print

d)

Replace

39.

Choose the correct syntax of the split function:

a)

x.split[]

b)

split(x)

c)

x.split(",", 3)

d)

X.SPLIT(",", 3)

40.

Choose the correct syntax of the replace function:

a)

x.Replace(x)

b)

x.replace(y)

c)

x.replace(3,x)

d)

x.replace("j","3")

41.

Choose the correct code to print line of 10 stars using repetition operation:

a)

print("**********")

b)

print("*"*10)

c)

print("*"^10)

d)

print("*"+10)

42.

The correct syntax of the len function for string x:

a)

x.len()

b)

len[x]

c)

LEN[]

d)

len(x)

43.

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

a)

X.upper()

b)

upper(x)

c)

x.UPPER[ ]

d)

x.upper()

44.

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

a)

myNAME.lower[ ]

b)

myname.lower( )

c)

myname.upper( )

d)

myname_lower(12 )

45.

To remove the spaces present at start and end of the string, you can use

a)

split()

b)

len()

c)

strip()

d)

remove()

46.

Let x= "Python", the output of print(x.upper()) is

a)

python

b)

PYTHON

c)

_PYTHON

d)

"PYTHON"

47.

Let x= "java", the output of Print(x.replace("j","L") ) is

a)

LAVA

b)

Error

c)

lava

d)

Lava

48.

Let x= "python is a high level language", the output of print(x[5].replace("n","*")) is

a)

pytho* is a high level language

b)

python is a high level language

c)

*

d)

Error

49.

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

a)

1

b)

31

c)

Error

d)

25

50.

Let x= "Python is a high level language", the output of print(x.replace(x[-3],"3")) is

a)

Error

b)

Python is 3 high level l3ngu3ge

c)

Python is a high l3v3l languag3

d)

Python is a high level language

51.

Let x= "Python is a high level language", the output of print(x[7].upper()) is

a)

Python is a high level language

b)

PYTHON IS A HIGH LEVEL LANGUAGE

c)

I

d)

S

52.

Let x= "Python is a high level language", the output of print(x[2].upper()+x[3].lower()+x[-1]) is

a)

THE

b)

The

c)

ThE

d)

the

53.

Let x= "Python is a high level language", the output of print(x[-4].upper()+x[8]+x[-1]) is

a)

Use

b)

Age

c)

USE

d)

Error

54.

Choose the correct python program that has the output 6

a)

print(len("Python"))

b)

Print(len("Python"))

c)

x= "Python"

print(x.replace("Python","6"))

d)

Both a and c

55.

Let x= "Python is a high level language", the output of

print(x.split("i", 2))

a)

['Pyth', 'n is a high level language']

b)

['Python is ', ' high level l', 'nguage']

c)

['Python ', 's a h', 'gh level language']

d)

Error

56.

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

57.

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

58.

What is a list in python?

a)

A collection of variables

b)

A collection of items assigned to a single variable

c)

A statement that cant be changed

d)

A Christmas list

59.

Which of these codes is correct for creating a list of numbers?

a)

num = ('10','29','37','109')

b)

num = ['10','29','37','109']

c)

num == ('10','29','37','109')

d)

num = ['10 29 37 109']

60.

What is the index number for 'Spain'?

['England','Brazil','Spain','France']

a)

0

b)

1

c)

2

d)

3

61.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

62.

Which code would i use to add an item to a list?

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

63.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

64.

Why is using lists beneficial?

a)

Shorter Code

b)

More Accurate

c)

It takes less time for the program to run

d)

Its not beneficial

65.

variable.sort() will do what?

a)

Sort the list into alphabetical order

b)

Sort the list into reverse order

c)

Create a new list

d)

Error

66.

What brackets are used to create a list?

a)

()

b)

[]

67.

What sort of loop is this?

a)

Count Controlled

b)

Condition Controlled

68.

What does the '#' allow you to do?

a)

Repeat code

b)

Comment on code

c)

Print code

d)

End code

69.

A condition controlled loop is...

a)

A while loop

b)

A for loop

70.

Which of these operators means EQUAL TO?

a)

'='

b)

'=>'

c)

'<='

d)

'=='

71.

What will this code do?

a)

Print Numbers 1-11

b)

Print Numbers 1-10

c)

Print Numbers 2-10

d)

Print Error