WorksheetsPython Semester 2 Checkpoint
Total questions: 38
Worksheet time: 23mins
What will be the output of the following code? ```python for i in range(3): print(i) ```
0 1 2 3
0 1 2
1 2 3
1 2
Which of the following is the correct way to define a function in Python?
`def myFunction:`
`function myFunction():`
`def myFunction():`
`myFunction() def:`
What will be the output of the following code? ```python def add(a, b): return a + b result = add(2, 3) print(result) ```
2
3
5
6
Which of the following is a correct way to pass parameters to a function?
`def myFunction(a, b):`
`def myFunction(a b):`
`def myFunction(a; b):`
`def myFunction(a b,):`
What will be the output of the following code? ```python def multiply(x, y): return x * y result = multiply(4, 5) print(result) ```
9
20
45
25
How do you loop through a list in Python?
`for i in list:`
`for i in range(list):`
`for i in len(list):`
`for i in list[]:`
What will be the output of the following code? ```python numbers = [1, 2, 3, 4] for number in numbers: print(number) ```
1 2 3 4
1 2 3
2 3 4
1 3 4
Which of the following is a correct way to return a value from a function?
`return value`
`return: value`
`returning value`
`return value;`
What will be the output of the following code? ```python def greet(name): return "Hello, " + name print(greet("Alice")) ```
Hello, Alice
Hello Alice
Hi, Alice
Hi Alice
Which of the following is a correct way to define a dictionary in Python?
`my_dict = {key1: value1, key2: value2}`
`my_dict = {key1 = value1, key2 = value2}`
`my_dict = {key1: value1; key2: value2}`
`my_dict = {key1, value1, key2, value2}`
What will be the output of the following code? ```python my_dict = {"name": "John", "age": 25} print(my_dict["name"]) ```
John
25
name
age
How do you access the value associated with a key in a dictionary?
`dict[key]`
`dict.key`
`dict(key)`
`dict{key}`
What will be the output of the following code? ```python def square(x): return x * x print(square(3)) ```
6
9
3
12
Which of the following is a correct way to loop through a dictionary in Python?
`for key in dict:`
`for key, value in dict:`
`for key in dict.keys():`
`for value in dict.values():`
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 1 b 2 c 3
a b c
1 2 3
a 1 b 2
__________ keyword is used for creating a function in Python.
define
fun
def
function
Function header in Python contains _________________.
function name
list of parameters
return type
all the above
Only A & B
what is dictionary in python
key value pair
collection of words
collections of functions
key output
Which of the following are true of Python dictionaries:
Dictionaries can be nested to any depth.
Dictionaries are accessed by key.
All the keys in a dictionary must be of the same type.
Dictionaries are mutable.
A dictionary can contain any object type except another dictionary.
Consider this dictionary:
d = {'foo': 100, 'bar': 200, 'baz': 300}
What is the result of this statement:
d['bar':'baz']
It raises an exception
(200, 300)
200 300
[200, 300]
Which two (2) lines of code will print when this function is called?
What is the name of the function?
When defining a function, the definition must occur before it is called.
true
false
What does the following code output?
11, 9
16, 16
None, None
225, 117
Which of the following is the correct code to define a function?
def area ( ):
area ( )
def area:
def area ( )
Which of the following terms best describes the code above?
function call
function definition
Line 6 is called
function definition
function call
function name
How many times will Boo print? /
Combien de fois Boo sera-t-il imprimé ?
What is the output?
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
What is the output?
False
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
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=10
a=20
syntax error
value error
