Font size
Worksheetspython ap1
Total questions: 40
Worksheet time: 1hrs 18mins
In a Python program, what would be the ending value for y in the WHILE LOOP code?
5
51
10
3
In a Python program, what would be the ending value of total in the WHILE LOOP code?
0
5
2
20
What is the output?
250.0
200.0
300.0
350.0
What is the output?
3
3
7
3
5
7
7
What is the output?
level 3
level 3
level 1
level 3
level 1
NIL
level 3
level 2
level 1
NIL
What is the output of the following if statement?
False
True
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
Which of the following is an advantage of using local variables?
They allow the variable to be used throughout the whole program
They allow variable identifiers to be reused each time
They are easier to program than global variables
A wider range of data types can be used
What will be the output of this program if the user enters "Han" and then "Solo"?
An error
Nothing
first surname
Han Solo
What is echo?
def shout_echo(word1, echo = 1):
default parameter, optional argument when call function
default argument, required parameter when call function
default argument, optional parameter when call function
default parameter, required argument when call function
What data type in the following function definition is used to send a flexible number of arguments to the function body?
def function_name(**kwargs)
dictionary
tuple
list
string
To catch an exception during program execution, use the try except clause.
True
False
Which of the following would return a ValueError message?
shout_echo("particle", echo=5)
shout_echo("particle")
shout_echo("particle", echo=-1)
shout_echo["particle", echo=5]
What will be the ouput -
f=open('abc.txt','w')
x=f.read()
f.close()
print(x)
Error(not readable)
Error(not writable)
It will read all the data of the file.
none
What will be the output-
f=open('abc.txt','a')
text="xyz"
f.write(text)
f.close()
Writing into the file without erasing old content
Writing into the file by erasing old content
reading from the file without erasing old content
reading from the file by erasing old content
The readlines() method returns
a. str
b. a list of lines
c. a list of single characters
d. a list of integers
What will be the output of the following Python code?
True
False
None
error
What type of inheritance is illustrated in the following Python code?
class A():
pass
class B():
pass
class C(A,B):
pass
Multi-level inheritance
Multiple inheritance
Hierarchical inheritance
Single-level inheritance
What will be the output of the following Python code?
class A:
def __init__(self):
self._x = 5
class B(A):
def display(self):
print(self._x)
def main():
obj = B()
obj.display()
main()
Error, invalid syntax for object declaration
Nothing is printed
5
Error, private class member can’t be accessed in a subclass
What will be the output of the following Python code?
class A:
def test1(self):
print(" test of A called ")
class B(A):
def test(self):
print(" test of B called ")
class C(A):
def test(self):
print(" test of C called ")
class D(B,C):
def test2(self):
print(" test of D called ")
obj=D()
obj.test()
test of B called
test of C called
test of C called
test of B called
test of B called
Error, both the classes from which D derives has same method test()
What will be the output of the following Python code?
>>> lamb = lambda x: x ** 3
>>> print(lamb(5))
15
555
125
Error
people = ["John", "Rob", "Bob"]
print (people[4])
what would this result be?
This code is equivalent to
random.randint(1,11)
random.randint(1,10)
random.randrange(1,11,1)
random.randrange(1,10,1)
What is the extension of python library modules?
.mod
.lib
.code
.py
Module that allows programs to output to calendars and provides other useful functions related to calendars.
datetime
calendar
time
date
Module that only provides date information (day, month and year).
datetime
calendar
time
date
Function used to get a the current date and time or to create a date object in Python using specified values.
datetime
strftime
strptime
dateutil
A point in time designated as the start of an era. For computers, the epoch date is the start of January 1, 1970.
epoch date
millisecond
microsecond
time start
Returns the time in seconds since the epoch, i.e., the point where the time starts.
timedelta
time.time( )
fromtimestamp( )
timestart( )
After inserting the data we need to issue
rollback
set autocommit
mycur.commit(1)
mycur.commit()
variable.sort() will do what?
Sort the list into alphabetical order
Sort the list into reverse order
Create a new list
Error
What is the function of the reverse method for lists?
removes the first occurrence of the information inside the parenthesis
adds the information inside the parenthesis to the end of the list
reverses the order of the elements inside a list
sorts the list (lowest to highest for numbers and alphabetical order for strings)
>>>x=5
>>>print "x"
What would be the result
5
type<int>
x
error variable x not found
