wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Certification Preparation

Total questions: 100

Worksheet time: 2hrs 39mins

Name
Class
Date
1.

What will be the output of the following code?

a)

['Batman', 'Superman', 'Wonder Woman', 'Flash', 'Aquaman']

b)

Cyborg

c)

Batman

d)

['Wonder Woman', 'Flash', 'Aquaman']

2.

What will be the output of the following code?

a)

Aquaman

b)

Cyborg

c)

Batman

d)

Superman

3.

What will be the output of the following code?

a)

['Aquaman', 'Batman', 'Cyborg', 'Flash', 'Superman', 'Wonder Woman']

b)

['Wonder Woman', 'Superman', 'Flash', 'Cyborg', 'Batman', 'Aquaman']

c)

['Cyborg', 'Aquaman', 'Flash', 'Wonder Woman', 'Superman', 'Batman']

d)

['Cyborg', 'Aquaman', 'Flash', 'Wonder Woman', 'Superman']

4.

What will be the output of the following code?

a)

True

b)

true

c)

False

d)

false

5.

Giving the code above, what would you need to type to print "Cyborg"?

a)

print(justiceLeague[1])

b)

print(justiceLeague[3])

c)

print(justiceLeague[2])

d)

print(justiceLeague[-1])

6.

How can we fix this text so that it prints as:

Michael Jordan is the "GOAT"

a)

text="Michael Jordan is the \"GOAT\""

b)

text="Michael Jordan is the /"GOAT/""

c)

text="Michael Jordan is the \\"GOAT\\""

d)

text="Michael Jordan is the//"GOAT//""

7.

What will be the output of the following code?

a)

True

b)

true

c)

False

d)

false

8.

Giving the code above, what would you need to type to print "Wonder Woman"?

a)

print(justiceLeague[6])

b)

print(justiceLeague[3])

c)

print(justiceLeague[2])

d)

print(justiceLeague[-1])

9.

What will be the output of the following code?

a)

10

b)

12

c)

22

d)

2

10.

Which escape sequence is for a new line?

a)

\n

b)

/n

c)

\\

d)

\b

11.

What will be the output of the following code?

a)

10

b)

12

c)

22

d)

2

12.

Which escape sequence is for a new line?

a)

\n

b)

/n

c)

\\

d)

\b

13.

Which escape sequence is for a tab?

a)

\t

b)

/t

c)

\b

d)

\f

14.

What will be the output of the following code?

a)

True

b)

true

c)

False

d)

false

15.

Which escape sequence is for a tab?

a)

\t

b)

/t

c)

\b

d)

\f

16.

Which escape sequence is for a backspace?

a)

\'

b)

/n

c)

\b

d)

\f

17.

Which escape sequence is for a form feed?

a)

\n

b)

\r

c)

\b

d)

\f

18.

When using Python in a command line environment, what command will list available Python commands and show information on these commands when an individual command is entered?

a)

help

b)

help()

c)

command()

d)

dir

19.

Which kind of error do you have when your program runs but the result are different from what you expect.

a)

Runtime

b)

Logic

c)

Syntax

20.

When using Python in a command line environment, what command will returns a list of valid attributes of the specified object? If no argument passed, it returns the list of names in the current local scope.

a)

dict()

b)

help()

c)

command()

d)

dir()

21.

Exception disrupts the

a)

Normal flow of the program

b)

Flow of the python interpreter

c)

Flow of memory on the hard disk

d)

None of the Above

22.

The unexpected event happened during program execution should be handled by

a)

Exception

b)

Experiment

c)

Assertion

d)

Termination

23.

Assume a = 10 and b = 5, then the output will be

a)

5.0

b)

Something Went Wrong

c)

Arithmetic Error

d)

2.0

24.

Choose the correct statement to close a file stream named myfile:

a)

myfile.terminate()

b)

myfile.end()

c)

myfile.close()

d)

myfile.remove()

25.

Assume a = ten and b = 5, then the output will be

a)

5.0

b)

Something Went Wrong

c)

Arithmetic Error

d)

2.0

26.

The suspicious code is put inside the

a)

Try Block

b)

Finally Block

c)

Else Block

d)

Except Block

27.

An exception can be manually triggered by the command

a)

raise

b)

try

c)

except

d)

trigger

28.

Assume a = ten and b = 5, then the output will be

a)

5.0

b)

Something Went Wrong

c)

Arithmetic Error

d)

2.0

29.

Which function is used to write multiple lines in text file?

a)

write()

b)

writelines()

c)

lines()

d)

print()

30.

Assume a = 10 and b = 5, then the output will be

a)

5.0

b)

Something Went Wrong

c)

Arithmetic Error

d)

2.0

31.

The unexpected event happened during program execution should be handled by

a)

Exception

b)

Experiment

c)

Assertion

d)

Termination

32.

Exception disrupts the

a)

Normal flow of the program

b)

Flow of the python interpreter

c)

Flow of memory on the hard disk

d)

None of the Above

33.

The suspicious code is put inside the

a)

Try Block

b)

Finally Block

c)

Else Block

d)

Except Block

34.

An exception can be manually triggered by the command

a)

raise

b)

try

c)

except

d)

trigger

35.

Is the following Python code valid?


try:

# Do something

except:

# Do something

else:

# Do something

a)

no, there is no such thing as else

b)

no, else cannot be used with except

c)

no, else must come before except

d)

yes

36.

What Python method lets the user enter an answer to a question via the keyboard?

a)

answer()

b)

open()

c)

print()

d)

input()

37.

What will be the output to the console for the code below?

print(3%6 )

a)

.5

b)

12

c)

2

d)

3

38.

Which of the following is not an exception handling keyword in Python?

a)

accept

b)

finally

c)

try

d)

except

39.

Which function is used to write multiple lines in text file?

a)

write()

b)

writelines()

c)

lines()

d)

print()

40.

What Python method lets the user read or write to a file?

a)

document()

b)

open()

c)

file()

d)

input()

41.

What will be the output to the console for the code below?

print(3%2 )

a)

2

b)

1

c)

0

d)

3

42.

What will be the output to the console for the code above?

a)

Isabel

b)

Evelyn

c)

Joseph

d)

Chris

43.

What Python method lets the user read or write to a file?

a)

document()

b)

open()

c)

file()

d)

input()

44.

n object of datetime that represents duration or a change in time and is used to calculate future and past times or dates.

a)

timedelta

b)

timediff

c)

timechange

d)

delta

45.

Python module handles the basic date and time classes for manipulating date and time. For manipulating times & dates together (month, day, year, hour, minute, second, microsecond).

a)

datetime

b)

calendar

c)

time

d)

date

46.

What is the order of resolving scope of a name in a python program?

a)

B E G L

b)

G E B L

c)

L E G B

d)

L B E G

47.

Method the provides 26 different items related to date and time that can be used in a Python program, returns as a string.

a)

datetime

b)

strftime

c)

strptime

d)

dateutil

48.

Method that accepts a string value and a format code that it converts into its' datetime equivalent.

a)

datetime

b)

strftime

c)

strptime

d)

dateutil

49.

Using the strftime() method, which one of the format specifiers below will produce an abbreviated display for the month of the year?

a)

%a

b)

%A

c)

%b

d)

%B

50.

How do we get user input from the keyboard?

a)

input = (What is your name?)

b)

input = What is your name?

c)

output = ("What is your name?")

d)

name=input("What is your name? ")

51.

What will be the output for the code above?

a)

Tue, Jan 04 2022

b)

Tuesday, January 04 2022

c)

Friday, April 01 2022

d)

Fri, Apr 01 22

52.

Using the strftime() method, which one of the format specifiers below will produce a hour (24-hour clock) as a zero-padded decimal number?

a)

%M

b)

%H

c)

%-H

d)

%I

53.
10= 100
Which of the following is used in Python to calculate ten squared?
a)
10 ** 2
b)
10 * 2
c)
10 % 2
d)
10 ** 10
54.

What will be the output for the code above?

a)

Wednesday, August 05 1981

b)

Wednesday, Aug 05 1981

c)

Wed, Aug 05 81

d)

Wed, Aug 05 1981

55.

Using the strftime() method, which one of the format specifiers below will produce an abbreviated display for the day of the week?

a)

%a

b)

%A

c)

%b

d)

%B

56.

What will be the output for the code above?

a)

2004-08-29

b)

2004-08-29 00:00:00

c)

08-29-2004 00:00:00

d)

08-29-2004

57.

What will be the output for the code above?

a)

2003-07-15 00:00:00

b)

2003-07-15

c)

07-15-2003 00:00:00

d)

07-15-2003

58.

What will be the output for the code above?

a)

20

b)

22

c)

1

d)

5

59.

For Hours(24 hrs format)

a)

%H

b)

%h

c)

%I

d)

%K

60.

What will be the output for the code above?

a)

10

b)

5

c)

1

d)

01

61.

What will be the output for the code above?

a)

2003-17-20 00:00:00

b)

2003-12-15 00:00:00

c)

2008-12-20 00:00:00

d)

2003-12-20 00:00:00

62.

Python mutable datatypes are ?

a)

list

b)

tuple

c)

set

d)

both list and set

63.

For Minutes we use

a)

%m

b)

%M

c)

%j

d)

%H

64.

What will be the output for the program above?

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'set'>

d)

<class 'dict'>

65.

Using the strftime() method, which one of the format specifiers below will produce a hour (12-hour clock) as a zero-padded decimal number?

a)

%M

b)

%H

c)

%-H

d)

%I

66.

What will be the output for the program above?

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'set'>

d)

<class 'dict'>

67.

What will be the output of the code below?

x=123.456

print(format(x, ".1f"))

a)

123.5

b)

123.456

c)

123.4

d)

123.45

68.

What will be the output for the program above?

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'set'>

d)

<class 'dict'>

69.

What symbol do you use to make a comment in Python?

a)

@

b)

//

c)

<!

d)

#

70.

What will be the output for the following program?

import datetime

date = datetime.datetime(2022,2,16)

offset =datetime.timedelta(days=2)

result = date + offset

time_data =result.strftime("%A")

print(time_data)

a)

February

b)

18

c)

2022

d)

Friday

71.

What will be the output of the code below?

x=123456789

print(format(x, "e"))

a)

123456789

b)

123456789.00

c)

1.234568e+08

d)

1.234560e+05

72.

Does python make a distinction between integers and floating variables?

a)

Yes

b)

No

73.

What will be the output of the code below?

x=123456789

print(format(x, ",d"))

a)

123456789

b)

123,456,789

c)

123_456_789

d)

123456789.00

74.

What will be the output of the code below?

x=0.78

print(format(x, "%"))

a)

78%

b)

78.0%

c)

78.000%

d)

78.000000%

75.

When using the open() function which mode will allow the user to open a file for appending, which will also create the file if it does not exist?

open("file", "mode")

a)

"r"

b)

"a"

c)

"w"

d)

"x"

76.

What will be the output of the code below?

x=123456789

print(format(x, "_d"))

a)

123456789

b)

123,456,789

c)

123_456_789

d)

123456789.00

77.

When is the finally block executed?

a)

when an exception occurs

b)

when no exception occurs

c)

never

d)

always

78.

What will be the output of the code below?

x=0.78

print(format(x, ".2%"))

a)

0.78%

b)

78.0%

c)

78.00%

d)

78.000000%

79.

When using the open() function which mode will allow the user to open a file for appending, which will also create the file if it does not exist?

open("file", "mode")

a)

"r"

b)

"a"

c)

"w"

d)

"x"

80.

What will be the output of the code below?

x=0.78

print(format(x, "f"))

a)

0.780000

b)

0.78

c)

78

d)

78.00

81.

When using the open() function which mode will allow the user to open a file for writing, creates the file if it does not exist?

open("file", "mode")

a)

"r"

b)

"a"

c)

"w"

d)

"x"

82.

Can one except block handle multiple exceptions?

a)

Yes

b)

No

c)

May be

d)

Insufficient information

83.

Do you agree with the statement: "Python is a statically typed language."

a)

No - it is dynamically typed

b)

Yes - it is indeed statically typed

84.

When using the open() function which mode will allow the user to creates the specified file, returns an error if the file exists?

open("file", "mode")

a)

"r"

b)

"a"

c)

"w"

d)

"x"

85.

How many except statements can a try-except statement have?

a)

None

b)

One

c)

Two

d)

Multiple

86.

When using the open() function which mode will allow the user to open a file for updating (reading and writing)?

open("file", "mode")

a)

"r"

b)

"r+"

c)

"w"

d)

"x"

87.

When will the else part of try-except-else be executed?

a)

always

b)

when an exception occurs

c)

when no exception occurs

d)

never

88.

When using the open() function which mode will allow the user to open a file for reading, error if the file does not exist?

open("file", "mode")

a)

"r"

b)

"a"

c)

"w"

d)

"x"

89.

What will be the output of the code above?

a)

ADGJMPSVY

b)

ABCDEFGHIJKLMNOPQRSTUVWXYZ

c)

ACEGIKMOQSUWY

d)

AEIMQ

90.

What will be the output of the code above?

a)

ADGJMPSVY

b)

ABCDEFGHIJKLMNOPQRSTUVWXYZ

c)

ZYXWVUTSRQPONMLKJIHGFEDCB

d)

ZYXWV

91.

What will be the output of the code above?

a)

['a', 'b', 'c', 'd', 'e']

b)

['e', 'd', 'c', 'b', 'a']

c)

['a', 'c', 'e']

d)

['e', 'c', 'a']

92.

What will be the output of the code above?

a)

['a', 'b', 'c', 'd', 'e']

b)

['e', 'd', 'c', 'b', 'a']

c)

['a', 'c', 'e']

d)

['e', 'c', 'a']

93.

What type of random numbers will this program print?

a)

All random integers from 0 to 100

b)

All even random integers from 0 to 99

c)

All odd random integers from 0 to 99

d)

All even random integers from 0 to 100

94.

What type of random numbers will this program print?

a)

All random integers from 1 to 100

b)

All even random integers from 1 to 99

c)

All odd random integers from 1 to 99

d)

All even random integers from 1 to 100

95.

What will be stored in variables 'a' after following statements?

perc=(88,85,80,88,83,86)

a=perc[2:-2]

a)

(80,88)

b)

(80,88,83)

c)

(88,80)

d)

(83,88,80)

96.

What will be the output to the console for the code above?

a)

2

4

b)

2

4

6

c)

0

1

2

3

d)

0

1

2

3

4

5

97.

What will be the output to the console for the code below?

print(20 / 2 )

a)

40

b)

4

c)

10

d)

10.0

98.

What will be the output to the console for the code below?

print(45 // 2 )

a)

22.0

b)

90

c)

22

d)

22.5

99.

What will be the output for the code above?

a)

[1, 2, 3, 4, 5]

b)

[1, 3, 4, 5]

c)

[1, 2, 4, 5]

d)

[3, 4, 5]

100.

What will be the output for the code above?

a)

[45, 50, 7, 8, 3, 41]

b)

[45]

c)

[45, 50, 7, 8, 3]

d)

[41, 50, 7, 8, 3, 45]