wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Semester 2 Checkpoint

Total questions: 38

Worksheet time: 23mins

Name
Class
Date
1.

What will be the output of the following code? ```python for i in range(3): print(i) ```

a)

0 1 2 3

b)

0 1 2

c)

1 2 3

d)

1 2

2.

Which of the following is the correct way to define a function in Python?

a)

`def myFunction:`

b)

`function myFunction():`

c)

`def myFunction():`

d)

`myFunction() def:`

3.

What will be the output of the following code? ```python def add(a, b): return a + b result = add(2, 3) print(result) ```

a)

2

b)

3

c)

5

d)

6

4.

Which of the following is a correct way to pass parameters to a function?

a)

`def myFunction(a, b):`

b)

`def myFunction(a b):`

c)

`def myFunction(a; b):`

d)

`def myFunction(a b,):`

5.

What will be the output of the following code? ```python def multiply(x, y): return x * y result = multiply(4, 5) print(result) ```

a)

9

b)

20

c)

45

d)

25

6.

How do you loop through a list in Python?

a)

`for i in list:`

b)

`for i in range(list):`

c)

`for i in len(list):`

d)

`for i in list[]:`

7.

What will be the output of the following code? ```python numbers = [1, 2, 3, 4] for number in numbers: print(number) ```

a)

1 2 3 4

b)

1 2 3

c)

2 3 4

d)

1 3 4

8.

Which of the following is a correct way to return a value from a function?

a)

`return value`

b)

`return: value`

c)

`returning value`

d)

`return value;`

9.

What will be the output of the following code? ```python def greet(name): return "Hello, " + name print(greet("Alice")) ```

a)

Hello, Alice

b)

Hello Alice

c)

Hi, Alice

d)

Hi Alice

10.

Which of the following is a correct way to define a dictionary in Python?

a)

`my_dict = {key1: value1, key2: value2}`

b)

`my_dict = {key1 = value1, key2 = value2}`

c)

`my_dict = {key1: value1; key2: value2}`

d)

`my_dict = {key1, value1, key2, value2}`

11.

What will be the output of the following code? ```python my_dict = {"name": "John", "age": 25} print(my_dict["name"]) ```

a)

John

b)

25

c)

name

d)

age

12.

How do you access the value associated with a key in a dictionary?

a)

`dict[key]`

b)

`dict.key`

c)

`dict(key)`

d)

`dict{key}`

13.

What will be the output of the following code? ```python def square(x): return x * x print(square(3)) ```

a)

6

b)

9

c)

3

d)

12

14.

Which of the following is a correct way to loop through a dictionary in Python?

a)

`for key in dict:`

b)

`for key, value in dict:`

c)

`for key in dict.keys():`

d)

`for value in dict.values():`

15.

What will be the output of the following code? ```python my_dict = {"a": 1, "b": 2, "c": 3} for key in my_dict: print(key, my_dict[key]) ```

a)

a 1 b 2 c 3

b)

a b c

c)

1 2 3

d)

a 1 b 2

16.

__________ keyword is used for creating a function in Python.

a)

define

b)

fun

c)

def

d)

function

17.

Function header in Python contains _________________.

a)

function name

b)

list of parameters

c)

return type

d)

all the above

e)

Only A & B

18.

what is dictionary in python

a)

key value pair

b)

collection of words

c)

collections of functions

d)

key output

19.

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.

20.

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]

21.

Which two (2) lines of code will print when this function is called?

4 lines
22.

What is the name of the function?

4 lines
23.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
24.

When defining a function, the definition must occur before it is called.

a)

true

b)

false

25.

What does the following code output?

a)

11, 9

b)

16, 16

c)

None, None

d)

225, 117

26.

Which of the following is the correct code to define a function?

a)

def area ( ):

b)

area ( )

c)

def area:

d)

def area ( )

27.
How do you correctly call this function
a)
def(1)
b)
x=square( )
c)
defSquare(4)
d)
x=square(5)
28.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
29.

Which of the following terms best describes the code above?

a)

function call

b)

function definition

30.

Line 6 is called

a)

function definition

b)

function call

c)

function name

31.
What will print?
a)
1 2
b)
1
c)
3
d)
5
32.

How many times will Boo print? /

Combien de fois Boo sera-t-il imprimé ?

a)
none
b)
4
c)
5
d)
1
33.

What is the output?

a)
Hello world!
b)
Hello world
c)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
d)
Error
34.

What is the output?

a)
Hello world!
b)
Error
c)
Hello world!
False
d)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
35.

What would happen if the user typed in "Python" as the first input?

---

Que se passerait-il si l'utilisateur tapait "Python" comme première entrée ?

a)
Welcome
b)
Try again!
c)
Error
d)
Enter your password
36.
a)

a=10

b)

a=20

c)

syntax error

d)

value error

37.
What will print ?
a)
cats eat mice
b)
mice get away
c)
unknown
d)
error message
38.
Which of the following best describes the order in which these lines are processed in Python?
a)
4, 1, 2
b)
4, 2, 1
c)
1, 2, 3, 4
d)
3, 1, 2