Worksheetspython-2
Total questions: 135
Worksheet time: 2hrs 41mins
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"]
Which of these codes is correct for creating a list of numbers?
num = ('10','29','37','109')
num = ['10','29','37','109']
num == ('10','29','37','109')
num = ['10 29 37 109']
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
What is used to separate elements in a list?
Bracket
Comma
Full Stop
Space
variable.sort() will do what?
Sort the list into alphabetical order
Sort the list into reverse order
Create a new list
Error
What does the '#' allow you to do?
Repeat code
Comment on code
Print code
End code
An empty list can be declared as
fruitList = ""
fruitList = ["empty"]
fruitList == []
fruitList = []
Each item in a list has an "address" or index. The first index in a Python list is what?
1
0
a
A
In programming, lists are often known as...
Arrays
Elements
Indexes
Data
What is the output of the following?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
[‘ab’, ‘cd’].
[‘AB’, ‘CD’].
None of the above
[None, None]
Which of the following commands will create a list?
a) list1 = list()
b) list1 = [].
c) list1 = list([1, 2, 3])
d) all of the mentioned
list1 = list()
list1 = [].
list1 = list([1, 2, 3])
all of the mentioned
Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ?
3
5
1
25
Suppose list1 is [1, 5, 9], what is sum(list1) ?
1
9
15
none
What will be the output?
names1 = ['Amir', 'Bala', 'Chales']
if 'amir' in names1:
print(1)
else: print(2)
None
1
2
error
Which of the following is the correct way to add the number 4 to mylist?
mylist + 4
mylist.append(4)
mylist.append([4])
4.append(mylist)
Which of the following commands will return the length of the list mylist?
length(mylist)
len(mylist)
mylist.length()
mylist.len()
What is the output of the following list assignment
aList = [4, 8, 12, 16]
aList[1:4] = [20, 24, 28]
print(aList)
[4, 20, 24, 28, 8, 12, 16]
[4, 20, 24, 28]
What is the output of the following list operation
aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:])
[20, 30, 40, 50]
[10, 20, 30, 40]
[30, 40, 50, 60, 70, 80]
[30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]
None of these
Select all the correct options to join two lists in Python
listOne = ['a', 'b', 'c', 'd']
listTwo = ['e', 'f', 'g']
newList = listOne + listTwo
newList = extend(listOne, listTwo)
newList = listOne.extend(listTwo)
newList.extend(listOne, listTwo)
What is the output of the following
aList = [5, 10, 15, 25]
print(aList[::-2])
[15, 10, 5]
[10, 5]
[25, 10]
What is the output of the following list function?
sampleList = [10, 20, 30, 40, 50]
sampleList.append(60)
print(sampleList)
sampleList.append(60)
print(sampleList)
[10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60, 60]
[10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60]
both are wrong
In Python, list is mutable
False
True
Which of the following would give an error?
list1=[]
list1=[]*3
list1=[2,8,7]
None of the above
What will be the output of below Python code?
list1=[8,0,9,5]
print(list1[::-1])
[5,9,0,8]
[8,0,9]
[8,0,9,5]
[0,9,5]
Which of the following will give output as [23,2,9,75] ?
If list1=[6,23,3,2,0,9,8,75]
print(list1[1:7:2])
print(list1[0:7:2])
print(list1[1:8:2])
print(list1[0:8:2])
Sort () function in list by default sort the values in __________
Ascending order
Decending order
Suppose list1 is [1, 3, 2], What is list1 * 2 ?
[2, 6, 4].
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']
Which display correct output from below ?
print(a[-5:-3])
['bar', 'baz']
print(a[4::-1])
['quux', 'baz', 'foo']
None
print(a[2])
['bar']
___________ method adds one list at the end of another list.
extend( )
append( )
insert( )
____________function can be used to insert an element/object at a specified index.
extend( )
insert ( )
append( )
___________method adds a single item to the end of the list.
extend( )
append( )
insert( )
how we store string value in variable?
'string'
"string"
%string%
#sring#
index of a string begins with
1
0
a
-1
The pseudocode below assigns two strings to two variables:
title = "computer science"
level = "gcse"
What would the Python code: len(level) return?
2
3
4
1
The pseudocode below assigns two strings to two variables:
title = "computer science"
level = "gcse"
What is title[0]?
'c'
'o'
'g'
An error
The pseudocode below assigns two strings to two variables:
title = "computer science"
level = "gcse"
What is title[4]?
'p'
'u'
't'
An error
string = "abcdef"
What is index of "f" ?
(a)
string = "Computer Science"
What is string[0:8] ?
(a)
Sequences of characters within a string can be accessed by taking a string ______ using [ ]
slice
cut
chop
substring
string1 = "Monty"
string2 = "Python"
string3 = string1 + string2
What is value of string3?
Monty Python
MontyPython
Monty+Python
string3
What does the isdigit() function do in Python?
Returns True if all the characters in the string are in capital letters
Returns True if all the characters in the string are in small letters
Returns True if the string contains only spaces
Returns True if all the characters in the string are digits
What is the output of the code fragment: print('hello'*3, str(123))?
hellohellohello, 123
hellohellohello, hellohellohello
hellohellohello, 123123123
hellohellohello, hello
Which of these will print the length of a string
print(len("a string"))
print("a string".len())
print(length("a string"))
x = len.string()
Which code would get the characters from position 2 to position 5 (not included).
x = txt[2:5]
x = txt[1:5]
x = txt[1:4]
x = txt[0[:4]
Convert the value of txt to upper case.
x = txt.upper()
x = txt.lower()
x = upper(txt)
x = upper.txt()
Replace the character H with a J
x = txt.replace("H", "J")
x = txt.replace("J", "H")
x = replace ("H", "J")
x = txt.replace(H,J)
Which keyword is used for function?*
define
fun
def
function
Which of the following items are present in the function header?
function name
parameter list
return value
Both A and B
If the return statement is not used inside the function, the function will return:
0
None
Null
Arbitary value
What is a recursive function?
A function that calls other function.
A function which calls itself.
Both A and B
None of the above
Which of the following function headers is correct?*
def fun(a = 2, b = 3, c)
def fun(a = 2, b, c = 3)
def fun(a, b = 2, c = 3)
def fun(a, b, c = 3, d)
In which part of memory does the system store the parameter and local variables of a function call?
heap
stack
Uninitialized data segment
None of the above
How is a function declared in Python?*
def function function_name():
declare function function_name():
def function_name():
declare function_name():
Which one of the following is the correct way of calling a function?
function_name()
call function_name()
ret function_name()
function function_name()
Which of the following functions is a built-in function in python?
array()
sqrt()
factorial()
print()
What will be the output of the following Python expression? round(4.576)
4.5
5
4
4.6
What will be the output of the following Python expression? round(4.5676,2)
4.5
4.6
4.57
4.56
A Python module is a file with the _____ file extension that contains valid Python code.
.pym
.pymodule
.module
.py
What is returned by math.ceil(3.4)?
3
4
4.0
3.0
Which statement is correct to import all modules from the package
from package import all
from package import *
from package include all
from package include *
(a) is a string literal denoted by triple quotes for providing the specifications of certain program elements.
Which of the following is not a valid namespace?
Global namespace
Public namespace
Built-in namespace
Local namespace
What is the order of namespaces in which Python looks for an identifier?
Python first searches the global namespace, then the local namespace and finally the built-in namespace
Python first searches the local namespace, then the global namespace and finally the built-in namespace
Python first searches the built-in namespace, then the global namespace and finally the local namespace
Python first searches the built-in namespace, then the local namespace and finally the global namespace
The collection of modules and packages that together cater to a specific type of applications or requirements, is called______
module
library
classes
documentation
The help statement display ___ from a module.
constants
functions
classes
docstrings
10#40#70#
30#40#50#
50#60#70#
40#50#70#
a=10
a=20
syntax error
value error
What is the Python function that adds an item on to the end of a list?
Extend
Append
Remove
Count
What is the Python Function for changing all lower case to upper case and all upper case to lower case letter?
upper
lower
replace
swapcase
What python function returns the number of items / characters in a list and string?
remove
pop
len
index
What is the python function that returns the number of times a specified item / character occurs in a list or string?
count
lower
concatenation
index
Which python code will return the character associated with the value 104.
chr(104)
ord(104)
str(104)
int(104)
What is the Python function that adds one list on to the end of another.
Extend
Append
Remove
Count
Which python function enables a new list item to be placed at any point in an existing list.
split
reverse
insert
pop
Which python function takes each word in a string and turns them into items of a list?
split
upper
replace
count
Which python function adds a capital letter to the first letter of a string?
lower
concatenation
capitalize
split
Which python code will add a new line to a python string?
\n
/t
\t
/n
What would be the output of the following python code?
True
False
Yes
No
What would be the output for the following python code?
True
No
False
Yes
What would be the output for the following python code?
worlD
World
world
WORLD
What would be the output for the following python code?
hello WORLD
HelloWORLD
helloWorld
helloWORLD
What would be the output for the following python code?
C
r
e
ter
What would be the output for the following python code?
['banana','cherry','orange']
['cherry','orange','kiwi']
['cherry','orange','kiwi','melon']
['banana','cherry','orange','kiwi']
What would be the output for the following python code?
['six', 'one', 'two', 'three', 'four', 'five']
['one', 'two', 'three', 'four', 'five', '6']
['one', 'two', 'three', 'four', 'five', 'six']
['one', 'two', 'three', 'four', 'five']
What would be the output for the following python code?
[5, 4, 3, 2, 1]
[12345]
[1, 2, 3, 5]
[1, 2, 3, 4, 5]
What would be the output for the following python code?
0
1
2
3
What would be the output for the following python code?
one
two
three
four
What is the output of the following lines of code?
var1 = 12
var1 = 23.4
var1 = "I love AI!"
print(var1)
12
23.4
I love AI!
Error
What is the output from the following lines of code?
a = [2, 4, 8]
a[2] = 6
print(a)
[2, 4, 8]
[2, 6, 8]
[2, 4, 6]
[6, 4, 8]
Which function allows us to add one element to a list at a desired location?
append()
extend()
insert()
pop()
How many parameters are there in the sum() function call below?
sum(1, 3, 5)
0
1
2
3
Which number is item, East, in the displayed list?
regions = ["North", "South", "East", "West"]
1
2
3
0
Which type of variable uses decimal?
String
Floating
Boolean
Integer
True or False? Variables cannot begin with a number.
True
False
True or False? Variables are case-sensitive
True
False
True or False? Variables must include at least one number
True
False
What is the modulus (%) of 17/4
4
1
7
3
What symbol concatenates variables in Python?
&
+
; )
*
Which number will be shown when the sales variable is run in a print statement
53235
30000
31000
32000
Which region and sales will come up based upon the print statement displayed on line 6?
West Sales; 35000
North Sales; 30000
South Sales; 20000
East Sales; 40000
Which number will the price variable show when the displayed code is run?
5
4
3
3.95
What syntax would you use to create a name variable?
name=input()
input=name
name=input{}
name=INPUT
What does the following code do? myAge = int(myAge)
Converts the variable myAge to a integer
Syntax Error
Converts the variable myAge from a integer to a string
Missing input
What will run when the following code is executed?
Count = 0
while count < 10:
print count
count += 1
0,1,2,3,4,5,6,7,8,9,10
0,1,2,3,4,5,6,7,8,9
1,2,3,4,5,6,7,8,9,
0,1,2,3,4,5,6,7,8,9,10,11
What will run when the following code is executed?
def my_function(x):
for i in range(0, len(x)):
x[i] = x[i]
return x
print my_function(range(5))
0,1,2,3,4,5
1,2,3,4,5
0,1,2,3,4
None of these choices
What will run when the following code is executed?
N = [3, 5, 7]
def double_list(x):
for i in range(0, len(x)):
x[i] = x[i] *2
3,10,7
6,10,14
3,5,7
[6,10,14]
What will run when the following code is executed?
N = [3, 5, 7]
def print_list(x):
for i in range(0, len(x)):
print x[i]
print_list(n)
3,5,7
[3,5,7]
{3,5,7}
None of the above
What will run when the following code is executed?
def list_function(x):
x[2] = x[2] +12
return x
n = [26, 29, 32]
print x[2]
32
29
44
None of these choices
What will run when the following code is executed?
N = [10, 20, 35]
n.append(42)
print n
10,20,35,42
{10,20,35,42}
*10,20,35,42*
[10,20,35,42]
What will run when the following code is executed?
N = [22, 13, 5]
N[0] = n[0] * 3
print N[0]
22
66
15
None of the above
What will run when the following code is executed?
n = [1,2,3,5,7,8]
print n[2]
2
3
5
7
What will run when the following code is executed?
n = [10, 15, 25, 35, 45]
n.append(14)
print n
10,15,25,35,45,14
[10,15,25,35,45,14]
{10,15,25,35,45}
None of these options
What will run when the following code is executed?
n = [0, 11, 13, 15, 22, 35]
n.pop(0)
print n
[0, 11, 13, 15, 22, 35]
[0,13, 15, 22, 35]
[0, 11, 13, 15, 22,]
[11, 13, 15, 22, 35]
What will run when the following code is executed?
def list_function(x):
x[1] = x[1] + 3
return x
n = [3, 5, 7]
print list_function(n)
3,5,7
[3,8,7]
3,8,7
{3,8,7}
What will run when the following code is executed?
n = [3, 5, 7]
def list_extender(lst):
lst.append(9)
return lst
print list_extender(n)
[9,3,5,7]
9,3,5,7
3,5,7,9
[3,5,7,9]
What is a condition?
A loop never exits
An expression that decides whether the loop is going to continue being executed or not
A statement that creates a function to determine the variance of a set of items
None of the above
What does the term “break” mean?
A function that has not defined properly
A loop that never exits
A one-line statement that means exit the current loop
None of the above
What does the “+=” represent?
The break statement
The number of items in a list
The increment of how much that specific count will run
None of the above
An “if” statement is an alternate way to stop a counting loop from running.
True
False
What does the term “.randint”?
Random Integer
A method of spell-check
An alternate way of "breaking" a counting loop
None of the above
In Python, the else block will continue to execute anytime the loop condition is evaluated to "False".
True
False
"String manipulation" is useful for loops if you want to modify some content in a string.
True
False
What does the term "enumerate" mean?
Works by supplying a corresponding index to each element in the list
Automatically sets the counting loops “start” number
Automatically sets the counting loops “end” number
None of the above
