WorksheetsPython challenge by Grade 8a Billabong Group
Total questions: 20
Worksheet time: 4mins
What does a for loop do in Python?
Repeats a block of code
Runs code only once
Creates a function
Stops the program
Which keyword is used to define a function?
func
define
def
function
What is the correct way to access the 2nd item in a list?
fruits = ["apple", "banana", "mango"]
fruits[0]
fruits[1]
fruits(1)
fruits{2}
What will be the output?
for i in range(3):
print("Hi")
Hi
HiHiHi
Hi (printed three times)
Error
Which is a string in Python?
"Hello"
56
True
[1, 2, 3]
Which of these adds an item to a list?
list.add()
list.append()
list.put()
list.insert() only
What does len("Python") return?
5
6
PYTHON
Error
A (a) loop continues until a condition becomes false.
A function returns a value using the (a) keyword.
Strings in Python are surrounded by ______ or ______.
(a)
The index of the first element in a list is (a) .
The command used to repeat code a fixed number of times is (a) .
What will this print?
name = "Computer"
print(name[2])
Computer
Error
Computer Computer
n
fruits = ["a", "b", "c", "d"]
print(fruits[-1])
a
b
c
d
def greet():
return "Hello!"
print(greet())
Hello!
Error
greet Hello
"Hello!"
for i in range(1, 4):
print(i)
1
2
3
1
2
3
4
1
2
Error
text = "hello"
print(text.upper())
Error
hello
"hello"
HELLO
Write a Python function named add that takes two numbers and returns their sum.
def add(a, b):
return a + b
def add(a, b)
return a + b
def add(a, b)
return a + b:
def add(a, b):
return a + b
Write a loop that prints numbers from 1 to 5.
for i in range(1, 6):
print(i)
for i in range(1, 5):
print(i)
for i in range(1, 6):
print(I)
for i in range(1, 6):
print(i)
Write a list of any 3 colors and print the first item.
colors = ["red", "blue", "green"]
print(colors1)
colors = ["red", "blue", "green"]
print(colors[0])
colors = ["red, "blue", "green"]
print(colors[0])
colors = ["red", "blue" "green")
print(colors[0])
