Font size
Worksheetstest
Total questions: 85
Worksheet time: 51mins
Is Python case sensitive when dealing with identifiers?
yes
no
What is the maximum possible length of an identifier?
31 characters
59 characters
10 characters
None of the mentioned
Which of the following is invalid?
_a = 1
__a = 1
__str__ = 1
none of the mentioned
Which of the following is an invalid variable?
my_string_1
1st_string
__
Which of the following is not a keyword?
eval
assert
nonlocal
pass
All keywords in Python are in
lower case
UPPER CASE
Capitalized
True, False and None are capitalized while the others are in lower case.
Which of the following is an invalid statement?
abc = 1,000,000
a b c = 1000 2000 3000
a,b,c = 1000, 2000, 3000
a_b_c = 1,000,000
Which of the following cannot be a variable?
__init__
in
it
on
What is the output of this expression, 3*1**3?
27
9
3
1
Which of these in not a core data type?
Lists
Dictionary
Class
Given a function that does not return any value, What value is thrown by default when executed in shell.
int
bool
void
none
Which of the following will run without errors ?
round(45.8)
round(6352.898,2,5)
round()
round(7463.123,2,1)
What is the return type of function id ?
int
float
bool
dict
What error occurs when you execute?
apple = mango
SyntaxError
NameError
ValueError
TypeError
Which of the following results in a SyntaxError ?
‘”Once upon a time…”, she said.’
“He said, ‘Yes!'”
‘3\’
”’That’s okay”’
What is the difference between a variable and a data type in Python?
A variable is a type of data, while a data type is a specific value in Python.
A variable is a name that refers to a value, while a data type specifies the type of data that a variable can hold.
A variable and a data type are the same thing in Python.
A variable is used for storing data temporarily, while a data type is used for performing operations in Python.
How do you write an if-else statement in Python?
if (condition) then { // code block } else { // code block }
if (condition) { // code block } else { // code block }
if condition { // code block } else { // code block }
if condition: # code block else: # code block
Explain the purpose of a function in Python and give an example.
The purpose of a function in Python is to display a message on the screen. For example, print('Hello, World!')
The purpose of a function in Python is to encapsulate a set of instructions that can be called multiple times to perform a specific task. For example, a function to calculate the area of a circle can be defined as follows: def calculate_area(radius): return 3.14 * radius * radius
The purpose of a function in Python is to define a variable. For example, x = 5
The purpose of a function in Python is to create a loop. For example, for i in range(5):
How would you add element to an existing list?
Using a function called append()
by writing the name of the list and element together
add_element() function
A list cannot be further modified.
How do you concatenate two strings in Python?
string1 . string2
string1 * string2
string1 + string2
string1 - string2
Write a for loop that prints numbers from 1 to 10.
for num in range(1, 11): print(num + 1)
for num in range(1, 10): print(num)
for num in range(10): print(num)
for num in range(1, 11): print(num)
Write a while loop that counts down from 10 to 1.
while count > 0: print(count) count -= 1
count = 10 while count > 0: print(count) count = count - 1
for i in range(10, 0, -1): print(i)
while count < 10: print(count) count += 1
What are the different types of operators in Python?
Arithmetic, Comparison, Logical, Assignment, Bitwise, Membership, Identity
Addition, Subtraction, Multiplication, Division
Equals, Not Equals, Greater Than, Less Than
If, Else, While, For
What is the purpose of using a dictionary in Python?
To store data in key-value pairs
To perform mathematical operations
To create loops for iteration
To define variables and data types
Write a Python function to calculate the factorial of a number.
def factorial(num): result = 1 for i in range(1, num + 1): result *= i return result
def factorial(num): result = 0 for i in range(1, num + 1): result += i return result
def factorial(num): result = 1 for i in range(1, num): result *= i return result
def factorial(num): result = 1 for i in range(1, num + 1): result += i return result
What is the purpose of using the 'break' statement in a loop in Python?
To skip the current iteration and continue with the next iteration
To exit the loop immediately
To execute a specific block of code when a condition is met
To repeat the loop for a specific number of times
What is the purpose of using the 'continue' statement in a loop in Python?
To skip the current iteration and continue with the next iteration
To exit the loop immediately
To execute a specific block of code when a condition is met
To repeat the loop for a specific number of times
What will be the output?
name = "Dave"
print (name)
Dave
'Dave'
name
(name)
It displays an output
What is the output from the following code?
print ("hello world")
What is the Python built-in function used to display numbers and text on the screen?
input
output
command
The punctuation requirements for printing a string in Python are:
( ) , ! and " "
( ) and !
( ) and " "
" " and !
What will be the output?
name = "Dave"
print ("name")
Dave
"Dave"
name
"name"
#How to you define an empty dictionary called myDict
myDict = " "
myDict = 0
myDict = [ ]
myDict = { }
#Which is the key and value
car = {"Brand" : "BMW"}
Key: Brand. Value: BMW
Key BMW, Value: Brand
{"Brand" : "BMW"}
"Brand" : "BMW"
#Can the keys in a dictionary be the same name?
Yes
No
#What is the output?
3
a,b,c
amt,bull,cow
6
#What is the output?
"A", "B", "C"
"Apple", "Banana","Carrot"
"A": "Apple", "B": "Banana", "C":"Carrot"
Error
#What is the output?
"Apple", "Banana", "Carrot"
"A","B","C"
"A": "Apple", "B": "Banana", "C":"Carrot"
Error
#How to print "Apple"
myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}
print(myDict["A"])
print(myDict[0])
print(myDict{0})
print(myDict{"A"})
#How to add "D": "Doughnut"
myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}
myDict["D"] = "Doughnut"
myDict[3] = "Doughnut"
myDict["D": "Doughnut"]
add myDict[3] "Doughnut"
#How to delete "B": Banana?
myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}
del myDict["B"]
del myDict["B": "Banana"]
del myDict[1]
del myDict{"B"}
#How to replace "B": "Banana" with "B": "Blueberries"
myDict = {"A": "Apple", "B": "Banana", "C":"Carrot"}
myDict["B"] = "Blueberries"
myDict["B":"Banana"] = myDict["B":"Blueberries"]
myDict["B"] = myDict["Blueberries"]
None of these
#What will be the output?
Error
{"abc":5}
abc
e
#Print "f"
myList[1][2]
myList[1][1]
myList[2]
myList[0][2]
#What is the output?
12.00
Error
Spicy
Tom Yum
#How to select RANDOM KEY from a Dictionary called "myDict"?
random.shuffle(myDict)
random.choice(myDict)
make a var to store myDict keys using keys() then random choice the var
It is not possible
#What is the output?
CR7
Manchester United
ronaldo
36
amount = 2 + 5 * 2
marks = 20
total = 5
newmarks = marks * 3
days = 5
if days > 6:
print(“Month”)
else:
print(“Week”)
team = “Manchester United”
letter = name[5]
print(letter)
for number in range(6):
print(number)
word= "computer"
for num in range(1,6):
print(word)
for loopCounter in range(10,101,10):
print(loopCounter)
name = “Alison”
number = len(name)
print(number)
while password != "computer":
print("Enter Password: ")
password = input()
names = ["Paul","Phillip","Paula","Phillipa"]
teams = [“Man Utd”,“Man City”,"Arsenal"]
teams.append(“Liverpool”)
Who invented python?
Alaxader Graham Bell
James Gosling
Guido Van Rossum
Is list a mutable data type?
True
False
Which two are a tuple in Python?
(99,100,101)
(11, 33, 77)
[11,22,33]
[2, 4, 6]
Python is a (a) language.
What will be the output of-
list1 = [51,52,53,54,55]
print (list1)
print (list1[4])
[51, 52, 53, 54, 55]
55
[51, 52, 53, 54, 55]
54
55
Error
Which of these is the best description of a list in Python?
A list is a collection of data that has an order and can be changed
A list is a lot of variables
A list is used for shopping
A list is a collection of data that cannot hold duplicated data and cannot be changed
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
List items have an index number. In the following list, which item has the index number of 3?
["John", "Harry", "Jesse", "John", "Harry", "Harry"]
"John"
"Harry"
"Jesse"
Which of these pieces of code would return the name "Harry" from the following list?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList()
nameList[1]
NameList(4)
nameList["4"]
The list needs one more name added to the end - "Felipe". Which piece of code below would do this?
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
What would this code do?
Remove the name "Felipe" from the list
Remove the first copy of "John" from the list
Remove the name "Felipe" from the list and print it out to the shell
An error
What would this code show on the screen?
7
6
5
4
An error
What would this code return on the shell?
Nothing
An error
"Woo hoo, you scored!"
"Raheem"
What would this code show in the shell?
3
2
1
0
An error
What would this code show in the shell?
3
2
1
0
An error
