wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python ap1

Total questions: 40

Worksheet time: 1hrs 18mins

Name
Class
Date
1.

In a Python program, what would be the ending value for y in the WHILE LOOP code?

a)

5

b)

51

c)

10

d)

3

2.

In a Python program, what would be the ending value of total in the WHILE LOOP code?

a)

0

b)

5

c)

2

d)

20

3.
A loop repeated if the condition is true / false
a)
While loop
b)
For loop
c)
Repeat loop
d)
If...else
4.
Loop executed a fixed number of times with a built-in-counter (creating a counter variable is unnecessary).
a)
While loop
b)
For loop
c)
Repeat loop
d)
If...else
5.
In programming, what is iteration?
a)
The repetition of steps within a program
b)
The order in which instructions are carried out
c)
A decision point in a program
d)
Testing a program to make sure it works
6.

What is the output?

a)

250.0

b)

200.0

c)

300.0

d)

350.0

7.

What is the output?

a)

3

b)

3

7

c)

3

5

7

d)

7

8.

What is the output?

a)

level 3

b)

level 3

level 1

c)

level 3

level 1

NIL

d)

level 3

level 2

level 1

NIL

9.

What is the output of the following if statement?

a)

False

b)

True

10.

What term is used to describe data passed into/out of a program?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

11.

Which of the following is an advantage of using local variables?

a)

They allow the variable to be used throughout the whole program

b)

They allow variable identifiers to be reused each time

c)

They are easier to program than global variables

d)

A wider range of data types can be used

12.

What will be the output of this program if the user enters "Han" and then "Solo"?

a)

An error

b)

Nothing

c)

first surname

d)

Han Solo

13.

What is echo?

def shout_echo(word1, echo = 1):

a)

default parameter, optional argument when call function

b)

default argument, required parameter when call function

c)

default argument, optional parameter when call function

d)

default parameter, required argument when call function

14.

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)

a)

dictionary

b)

tuple

c)

list

d)

string

15.

To catch an exception during program execution, use the try except clause.

a)

True

b)

False

16.

Which of the following would return a ValueError message?

a)

shout_echo("particle", echo=5)

b)

shout_echo("particle")

c)

shout_echo("particle", echo=-1)

d)

shout_echo["particle", echo=5]

17.

What will be the ouput -

f=open('abc.txt','w')

x=f.read()

f.close()

print(x)

a)

Error(not readable)

b)

Error(not writable)

c)

It will read all the data of the file.

d)

none

18.

What will be the output-

f=open('abc.txt','a')

text="xyz"

f.write(text)

f.close()

a)

Writing into the file without erasing old content

b)

Writing into the file by erasing old content

c)

reading from the file without erasing old content

d)

reading from the file by erasing old content

19.

The readlines() method returns

a)

a. str

b)

b. a list of lines

c)

c. a list of single characters

d)

d. a list of integers

20.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

error

21.

What type of inheritance is illustrated in the following Python code?

class A():

pass

class B():

pass

class C(A,B):

pass

a)

Multi-level inheritance

b)

Multiple inheritance

c)

Hierarchical inheritance

d)

Single-level inheritance

22.

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()

a)

Error, invalid syntax for object declaration

b)

Nothing is printed

c)

5

d)

Error, private class member can’t be accessed in a subclass

23.

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()

a)

test of B called

test of C called

b)

test of C called

test of B called

c)

test of B called

d)

Error, both the classes from which D derives has same method test()

24.
These have identitystate, and behavior.
a)
class
b)
object
c)
method
d)
void
25.

What will be the output of the following Python code?

>>> lamb = lambda x: x ** 3

>>> print(lamb(5))

a)

15

b)

555

c)

125

d)

Error

26.

people = ["John", "Rob", "Bob"]

print (people[4])

what would this result be?

a)
John
b)
Rob
c)
Bob
d)
Error
27.
_______ is used to search through a string starting at its beginning. It returns None if no match is found.
a)
re.match()
b)
re.Search()
c)
re.Method()
d)
re.search()
28.
Which flag will search over multiple lines?
a)
re.ml
b)
re.M
c)
re.m
d)
re.ML
29.
Which flag will make your search case-insensitive?
a)
re.I
b)
re.c-i
c)
re.CI
d)
re.C-I
30.

This code is equivalent to

a)

random.randint(1,11)

b)

random.randint(1,10)

c)

random.randrange(1,11,1)

d)

random.randrange(1,10,1)

31.

What is the extension of python library modules?

a)

.mod

b)

.lib

c)

.code

d)

.py

32.

Module that allows programs to output to calendars and provides other useful functions related to calendars.

a)

datetime

b)

calendar

c)

time

d)

date

33.

Module that only provides date information (day, month and year).

a)

datetime

b)

calendar

c)

time

d)

date

34.

Function used to get a the current date and time or to create a date object in Python using specified values.

a)

datetime

b)

strftime

c)

strptime

d)

dateutil

35.

A point in time designated as the start of an era. For computers, the epoch date is the start of January 1, 1970.

a)

epoch date

b)

millisecond

c)

microsecond

d)

time start

36.

Returns the time in seconds since the epoch, i.e., the point where the time starts.

a)

timedelta

b)

time.time( )

c)

fromtimestamp( )

d)

timestart( )

37.

After inserting the data we need to issue

a)

rollback

b)

set autocommit

c)

mycur.commit(1)

d)

mycur.commit()

38.

variable.sort() will do what?

a)

Sort the list into alphabetical order

b)

Sort the list into reverse order

c)

Create a new list

d)

Error

39.

What is the function of the reverse method for lists?

a)

removes the first occurrence of the information inside the parenthesis

b)

adds the information inside the parenthesis to the end of the list

c)

reverses the order of the elements inside a list

d)

sorts the list (lowest to highest for numbers and alphabetical order for strings)

40.

>>>x=5

>>>print "x"

What would be the result

a)

5

b)

type<int>

c)

x

d)

error variable x not found