NEW
Font size
WorksheetsPython Quiz for Grade 8
Total questions: 24
Worksheet time: 12mins
What will the following code output?
st = "Python"
print(st[2])
P
y
t
h
What does len('Hello World') return?
10
11
12
9
What is the output of
print ("Hello" + " World")?
Hello World
HelloWorld
Error
Hello
How many times will this loop run?
for i in range(3):
print(i)
2
3
4
0
What is the output of:
for i in range(2, 5):
print(i)
2, 3, 4
2, 3, 4, 5
3, 4, 5
None
What does range(5, 10, 2) produce?
5, 6, 7, 8, 9
5, 7, 9
6, 8, 10
5, 10
What is the output of the following function?
def greet():
print('Hello')
greet()
Hello
Error
None
greet
What does this function return?
def add(a, b):
return a + b
print(add(2, 3))
2
3
5
Error
Which is a correct function definition?
def my_function a, b):
def my_function(a, b):
function my_function(a, b):
my_function def(a, b):
What is the output of:
def repeat(word):
return word * 2
print(repeat('Hi'))
HiHi
Hi Hi
Hi2
Error
What will the following code output?
def my_func():
return 'Hi'
print(my_func() + ' there!')
Hi there!
HiThere!
Error
None
What does len('Hello World') return?
10
11
12
9
How many times will this loop run? for i in range(3): print(i)
2
3
4
0
What is the output of: for i in range(2, 5): print(i)
2, 3, 4
2, 3, 4, 5
3, 4, 5
None
What does range(5, 10, 2) produce?
5, 6, 7, 8, 9
5, 7, 9
6, 8, 10
5, 10
What is the output of the following function? def greet(): print('Hello') greet()
Hello
Error
None
greet
What does this function return? def add(a, b): return a + b print(add(2, 3))
2
3
5
Error
Which is a correct function definition?
def my_function a, b):
def my_function(a, b):
function my_function(a, b):
my_function def(a, b):
What is the output of: def repeat(word): return word * 2 print(repeat('Hi'))
HiHi
Hi Hi
Hi2
Error
What will the following code output? print('Python'[2])
P
y
t
h
What does len('Hello World') return?
10
11
12
9
What is the output of 'Hello' + ' ' + 'World'?
Hello World
HelloWorld
Error
Hello
How many times will this loop run? for i in range(3): print(i)
2
3
4
0
What is the output of: for i in range(2, 5): print(i)
2, 3, 4
2, 3, 4, 5
3, 4, 5
None
