wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python PCEP

Total questions: 150

Worksheet time: 2hrs 45mins

Name
Class
Date
1.

What will the output be after executing the following code snippet?

a)

3

b)

9

c)

1

d)

18

2.

What will the output be, if we run the following code?

a)

Monday, Tuesday, Wednesday, Thursday

b)

Friday

c)

None

d)

AttributeError: 'tuple' object has no attribute 'append'

3.

How many times will it print "#"?

a)

1

b)

2

c)

3

d)

4

4.

What is the output of this code when "robert" is entered by the user when prompted?

a)

True

b)

error

c)

Robert

d)

False

5.

What would be printed to the console after the following code is executed?

a)

Hello

b)

"Hello", World

c)

Hello World

d)

Hello, World

6.

What will the output be after executing the following code?

a)

('Python', 'Tuple')

b)

[Python, Tuple]

c)

['Python', 'Tuple']

d)

(Python, Tuple)

7.

What is the output when the following code snippet is run:

a)

Error

b)

None

c)

Let's enjoy a bowl of cereals

d)

Groceries trip pending

8.

What will the output be after executing the following code?

a)

[6]

b)

[0, 1, 2, 3, 4, 5]

c)

-6

d)

(0,1,2,3,4)

9.

What will the output be after executing the following code?

a)

dict{'Python', 'Dictionaries'}

b)

dict({'Python', 'Dictionaries'})

c)

{'Python', 'Dictionaries'}

d)

{1: 'Python', 2: 'Dictionaries'}

10.

What is the output of this code after the user inputs "Python" when prompted?

a)

PythonPythonPython

b)

error

c)

Python*3

d)

Python Python Python

11.

What will the output be after running the following code?

a)

[0,1,2,3,4,5]

b)

(0,1,2,3,4,5,6)

c)

[0, 1, 2, 3, 4, 6]

d)

[1,2,3,4,5,6]

12.

What will the output be, if we execute the following code?

a)

{'Name': 'Python', [1, 2, 3, 4], 'hi'}

b)

{'Name': 'Python', 1: [1, 2, 3, 4], 2: 'hi'}

c)

Syntax Error

d)

{'Python', [1, 2, 3, 4], 'hi'}

13.

What will the output be, if we run the following code?

a)

0 1

1 1

0 0

1 0

b)

0 1

0 0

1 1

1 0

c)

0 1

0 0

1 0

1 1

d)

0 1

1 1

1 0

0 0

14.

What will the output be after executing the following code?

a)

Hello "\nPython!"

b)

Hello Python!

c)

Hello

Python!

d)

Hello \nPython!

15.

What will the output be after running the following code snippet?

a)

Robert method karamagi

b)

Robert method Karamagi

c)

Robert Method Karamagi

d)

ROBERT METHOD KARAMAGI

16.

What will the output be after calling the following function?

a)

6

b)

Syntax Error

c)

6 5

d)

5

17.

What will the output be after running the following code snippet?

a)

19

b)

Syntax Error

c)

True

d)

False

18.

What would be printed to the console after the following code is

executed?

a)

2,4,6,8,10,

b)

2,4,6,8,

c)

1,3,5,7,9,

d)

1,3,7,9,

19.

What will the output be after executing the following code snippet?

a)

Nothing is printed

b)

3

c)

-1

d)

P

20.

What will the output be, if we run the following code?

a)

No Output

b)

{1: One, 2: Two}

c)

{1:"One", 2:"One"}

d)

{1: "One",1 : "One"}

21.

What will the output be after running the following code?

a)

[1, 2, 3, 4, 5, 6]

b)

[7, 6, 5, 4, 3, 2, 1]

c)

[0, 1, 2, 3, 4, 5, 6]

d)

[7, 1, 2, 3, 4, 5, 6]

22.

What is the output of this code when 'wi' and 'fi' are entered by the user

when prompted and stored in a and b, respectively?

a)

wifiwiwifi

b)

wifiwifiwifi

c)

wifififi

d)

wififififi

23.

What will the output be after executing the following code?

a)

Hello#World#Python

b)

error

c)

#Hello#World#Python

d)

HelloWorldPython#

24.

What is the output of the following code?

a)

error

b)

4

c)

2

d)

1

25.

What is the output of the following code?

a)

error

b)

<class 'int'>

c)

<class 'tuple'>

d)

Invalid Data Type

26.

What will the output be after running the following code?

a)

odd

b)

even

27.

What will the output be after running the following code?

a)

error

b)

5 10

c)

10 5

d)

Prints nothing

28.

What will the output be after running the following code?

a)

Prints nothing

b)

1 5

c)

error

d)

5 1

29.

Will the following code run without errors?

a)

This code will run without errors.

b)

This code will not run.

30.

What is the output after executing the following code?

a)

Oranges Mangoes

b)

Apple Mangoes

c)

Apple Oranges

d)

Apple Oranges Mangoes

31.

What do you expect the following code will print given the first input is

apple (stored in variable a) and the second input is banana (stored in

variable b)?

a)

apple:banana

b)

apple::banana

c)

banana:apple:

d)

banana::apple

32.

What will the output be after running the following code snippet?

a)

0

b)

4

c)

2

d)

1

33.

What will the output be after running the following code snippet?

a)

['bananas', '']

b)

['bananas']

c)

['apples']

d)

['apples', 'bananas', '']

34.

What will the output be after running the following code snippet?

a)

[7, 6, 5, 4, 3, 2, 1]

b)

[1, 2, 3, 4, 5, 6, 7]

c)

[1, 2, 3, 4, 5, 6]

d)

[2, 3, 4, 5, 6, 7]

35.

What will the output be after running the following code snippet?

a)

0b01

b)

0b11

c)

0b10

d)

10

36.

What is the output of the following program?

a)

1

b)

9

c)

10

d)

90

37.

What will the output be after running the following code snippet?

a)

Not equal

b)

Equal

c)

False

d)

True

38.

What will the output be after running the following code snippet?

a)

4

b)

error

c)

1

d)

9

39.

What is the output of the following snippet of code:

a)

2

b)

3

c)

Nothing is printed

d)

0

40.

What will the output be after running the following code snippet?

a)

Values are the same

b)

Values are different

c)

True

d)

False

41.

What do you expect the following code to print:

a)

[5, 4, 3, 2, 1]

b)

[1, 2, 3, 4, 5]

c)

[1, 2, 3, 4]

d)

[5, 1, 2, 3, 4]

42.

What will the output be after running the following code snippet?

a)

100

b)

20

c)

error

d)

x not defined

43.

What will the output be after running the following code snippet?

a)

[1, 1, 2, 2, 3, 3]

b)

[1, 2, 3, 1, 2, 3]

c)

[1, 2, 3, 3, 2, 1]

d)

[1, 2, 3]

44.

What will the output be after executing the following code snippet?

a)

error

b)

Yes

c)

No

d)

0

45.

What will the output be after running the following code snippet?

a)

hello prof karamagi

b)

HelloProfKaramagi

c)

Hello prof karamagi

d)

Hello Prof Karamagi

46.

What will the output be after running the following code snippet?

a)

(1, 2, 3), ('apples', 'banana', pears')

b)

(1, 2, 3) + ('apple', 'banana'. 'pears')

c)

(1, 2, 3, 'apples', 'banana', 'pears')

d)

('apple, 'banana', 'pears', 1, 2, 3)

47.

What will happen if the following snippet of code is executed?

a)

Hello ""

b)

Hello "name"

c)

Hello, name

d)

Hello

48.

What will the output be after running the following code snippet?

a)

Robert,Karamagi

b)

Robert ","Karamagi

c)

Robert Karamagi

d)

RobertKaramagi

49.

What will the output be after running the following code snippet?

a)

No Class

b)

First Class

c)

Second Class

d)

Third Class

50.

What will the output be after running the following code snippet?

a)

64

b)

12

c)

7

d)

6

51.

What will the output be after running the following code snippet?

a)

--

b)

"

c)

Nothing; no newline/blank

d)

'--'

52.

What will the output be after running the following code snippet?

a)

[[10, 2, 3]]

b)

[[1, 2, 3]]

c)

[[10, 1, 2, 3]]

d)

[[10]]

53.

What will the output be after running the following code snippet?

a)

not valid

b)

greater than 10

c)

less than 10

d)

syntax error

54.

What will the output be after running the following code snippet?

a)

{'one': 0, 'two': 1}

b)

{'one': 0, 'two': 2}

c)

{'one': 1, 'two': 2}

d)

{'one': 1, 'two': 0}

55.

What will the output be after running the following code snippet?

a)

Python,Python

b)

Python','Python

c)

PythonPython

d)

Python,*2

56.

What will the output be after running the following code snippet?

a)

error

b)

('Peter', 'Piper', 'Pickled', 'Pepper')

c)

('Peter')

d)

['Peter', 'Piper', 'Pickled', 'Pepper']

57.

What do you expect to be output to the console?

a)

False

b)

True

c)

Python is Awesome!

d)

Hello, World!

58.

What will the output be after running the following code snippet?

a)

error

b)

2

c)

2.0

d)

5

59.

What do you expect the following code snippet to printout:

a)

('P', 'y', 't', 'h', 'o', 'n')

b)

('W', 'o', 'r', 'l', 'd', '!')

c)

('n', 'o', 'h', 't', 'y', 'P')

d)

[P, y, t, h, o, n]

60.

What will the output be after running the following code snippet?

a)

6

b)

4

c)

9

d)

error

61.

What will be the output after running the following code?

a)

func1

func3

func3

b)

func3

func3

func1

c)

func1

func2

func3

d)

func3

func2

func1

62.

What will be the output after running the following code?

a)

[7, 2]

b)

[7, 6, 5, 4, 3, 2]

c)

[7, 3]

d)

SyntaxError

63.

What will be the output after running the following code?

a)

Yes

b)

True

c)

error

d)

No

64.

What will be the output when the following program is run?

a)

5,4,'Earth'

b)

[5,4]

c)

[5, 4, 'Earth']

d)

{5,4,'Earth'}

65.

What is the output of the following code:

a)

<class 'tuple'>

b)

<class 'list'><class 'int'>

c)

<class 'list'>

d)

error

66.

What will the output be after executing this code?

a)

True True False

b)

False False True

c)

False True False

d)

False False False

67.

What is the output of the following print statement ?

a)

False

b)

True

c)

SyntaxError

d)

10

68.

What is the output when the following code is executed:

a)

['o', 'u']

b)

['a', 'e', 'i']

c)

['a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u']

d)

['a', 'e', 'i', 'o', 'u']

69.

What will be the output after running the following code?

a)

AttributeError

b)

['Tuple']

c)

[]

d)

['Python']

70.

What do we need to change in order to fix the following code:

a)

error as the variable name str is invalid

b)

None of the above

c)

Wrap the whole sentence in a single quotes and leave Piper and Pepper in double quotes as is

d)

Escape the quotes around Piper and Pepper words using the \ character.

71.

What would the following program print to the console when user inputs 3 and 'Python' to be stored in the a and b variables respectively?

a)

"Python Python Python"

b)

Python

c)

PythonPythonPython

d)

SyntaxError

72.

What do you expect the following code to produce?

a)

G

b)

Good Night

c)

Good Morning

d)

Go

73.

What will be the output after running the following code?

a)

(1, 2, 3, 'Apples', 'Bananas')

b)

SyntaxError

c)

(1, 2, 3)('Apples', 'Bananas')

d)

('Apples', 'Bananas', 1, 2, 3)

74.

Given x and y are two binary numbers, what would the AND (&) operator on these number yield?

a)

0b110

b)

0b101

c)

0b001

d)

0b100

75.

What do you expect the following print statement to produce ?

a)

False

b)

Butter

c)

"Butter"

d)

True

76.

What will be the output after running the following code?

a)

False

b)

Error

c)

hi

d)

bye

77.

What will the output be after executing this code?

a)

error

b)

The program will infinitely print {'blue' : 1,'red' : 2,'yellow': 3} .

c)

{'blue' : 1,'red' : 2,'yellow': 3}

d)

Nothing is printed

78.

What do you expect the following code to print out:

a)

1

b)

2

c)

5

d)

error

79.

What will be the output when the following program is run?

a)

Hello World Python

b)

Hello World

c)

HelloWorld Python

d)

HelloWorldPython

80.

What will be the output after running the following code?

a)

1 : 1

b)

1 : 2

c)

2 : 2

d)

2 : 1

81.

What will be the output after running the following code?

a)

9

b)

9+y

c)

0

d)

error

82.

What will the output be after executing the following code?

a)

apples

bananas

b)

error

c)

1 apples

1 bananas

d)

1 apples

2 bananas

83.

What is the output of the following print statement:

a)

Knowledge Is Power

b)

KnowledgeIsPower

c)

error

d)

"Knowledge Is Power"

84.

What will be the output after running the following code?

a)

error

b)

Java

c)

Python

d)

1

85.

What will the output be when the following code is executed?

a)

Invalid input

b)

5

c)

6

d)

7

86.

What will be the output after running the following code?

a)

1

b)

[('first', 3),('third', 2)]

c)

[('first', 3),(1),('third', 2)]

d)

second

87.

What will the output be after running the following code snippet?

a)

0,1,2,3,4,5

b)

6

c)

1,2,3,4,5,6

d)

5

88.

What is the output of the following code:

a)

[1, 2, 3][1, 2, 3]

b)

error

c)

[4, 5, 6, 7] [1, 2, 3]

d)

[1, 2, 3][4, 5, 6, 7]

89.

What is the output of the following code:

a)

40

b)

100

c)

20

d)

200

90.

What is the output of the following code:

a)

10

b)

error

c)

9

d)

5

91.

What will be the output after running the following code?

a)

45

b)

10

c)

1

d)

55

92.

What will be the output after running the following code?

a)

['bananas', 'apples', 'strawberries', 'peas']

b)

['bananas', 'apples', 'pears', 'strawberries']

c)

['bananas', 'apples', 'strawberries']

d)

['strawberries', 'strawberries', 'strawberries']

93.

What will be the output after running the following code?

a)

8

b)

27

c)

216

d)

error

94.

What will be the output after running the following code?

a)

1 1

b)

error

c)

0 0

d)

0 1

95.

What does the following code do?

a)

2.0

b)

0.5

c)

0

d)

2

96.

What will be the output after running the following code?

a)

3.0

b)

3

c)

TypeError

d)

21.0

97.

What will be the output after running the following code?

a)

8hi

b)

2hi

c)

hi

d)

4hi

98.

Mark the correct sentence about the break statement in a for loop?

a)

Break statement does not affect flow of the loop

b)

Break will terminate the current iteration but will resume with the next iteration

c)

Break will terminate the entire loop

d)

Break statement in an inner loop will terminate the both inner and outer loop

99.

What will be the output after running the following code?

a)

Value of i : i

b)

Value of i : 6

c)

6

d)

SyntaxError

100.

What will be the output after running the following code?

a)

0b1110

b)

0b1111

c)

0b1101

d)

0b1100

101.

What will be the output after running the following code?

a)

["Tuesday", "Monday", "Wednesday", "Thursday", "Friday"]

b)

[ "Monday", "Tuesday, "Wednesday", "Thursday", "Friday"]

c)

["Monday", "Wednesday", "Thursday"]

d)

["Tuesday","Friday", "Monday", "Wednesday", "Thursday"]

102.

What is the output of the code below:

a)

60

90

b)

90

60

c)

90

d)

60

103.

What will be the output after running the following code?

a)

Earth

b)

Earth Jupiter

c)

2

d)

2 True

104.

What will be the output after the following code is executed?

a)

Hello World

b)

HelloWorld

c)

HelloNoneWorld

d)

Hello,World

105.

What will be the output after running the following code?

a)

((-1, 0, 1), 'bananas')

b)

(-1, 0, 1, 'bananas')

c)

(-1, 0, 1)('bananas')

d)

('bananas', (-1, 0, 1))

106.

What will be the output after running the following code?

a)

2

b)

0.4

c)

SyntaxError

d)

2.5

107.

What will be the output after running the following code?

a)

Fixed

b)

Temp

c)

error

d)

True

108.

What is the output of this code when 'Robert' and 13 are entered by the user and stored in variables name and age, respectively?

a)

Robert <class 'int'>

b)

Robert 13(int)

c)

Robert 13

d)

SyntaxError

109.

What will be the output after running the following code?

a)

0 1 2

b)

1 2 3

c)

0 1 2 2

d)

0 1 2 3

110.

What will be the output after the following code is executed?

a)

not True

b)

False

c)

not False

d)

True

111.

What will be the output after running the following code?

a)

['Python', 'weekends', ['Saturday', Sunday']]

b)

{'Python', ["Saturday", "Sunday"]}

c)

IndexError

d)

{0: 'Python', 'weekends': ['Saturday', 'Sunday']}

112.

What will be the output of the following code?

a)

A blank space

b)

error

c)

A blank line

d)

Nothing is printed

113.

What is the output when the following program is executed?

a)

[3.14, True]

b)

['apples', 3.14, True]

c)

[1, "apples", 3.14, True]

d)

[1, 2, "apples"]

114.

What do you expect the following code to produce:

a)

error

b)

Good Morning

c)

Good Night

d)

Good name=""

115.

What will be the output after running the following code?

a)

36

b)

30

c)

error

d)

invalid input

116.

Is this the correct way to write the code?

a)

No, the syntax is incorrect

b)

Yes, the syntax is correct

117.

What will be the output after running the following code?

a)

False

b)

True

c)

error

d)

hello

118.

What will be the output after running the following code?

a)

[1, 2, 3, 2, 1]

b)

[1, 1, 2, 2, 3]

c)

[1, 2, 3, 1, 2]

d)

error

119.

What will be the output after running the following code?

a)

not equal

b)

False

c)

True

d)

equal

120.

What will be the output after running the following code?

a)

('Python', 'World', 'Python', 'World')

b)

error

c)

('Python', 'World')('Python', 'World',)

d)

('Python', 'World', 2)

121.

Which of the following statements is incorrect:

a)

An indentation in Python language is mandatory

b)

The '#' is used as single line comments and the """ """ (triple quote) is used as multi-line comments

c)

We don't need to declare the type of a variable in Python program

d)

All of these are correct.

122.

What will the output be when the following code is executed?

a)

"Robert, 123455667, Dar es salaam "

b)

Robert 123455667 Dar es salaam

c)

SyntaxError

d)

Robert' 123455667 'Dar es salaam '

123.

What will be the output when the following code is executed?

a)

\n:\n:\n

b)

:

:

:

c)

Three blank lines

d)

error

124.

What will be the output when the following code is executed?

a)

25

b)

256

c)

error

d)

25.6

125.

Which of the following statements is incorrect (select all that apply):

a)

The bool("123") will return True

b)

The bool("") will return True

c)

The bool({}) will return False

d)

The bool(-1) will return False

126.

What would be the output of the following code:

a)

1

b)

2

c)

4

d)

25

127.

What will be the output when the following code is executed?

a)

False

b)

True

c)

SyntaxError

d)

error

128.

What will be the output when the follownig code is executed?

a)

0b00111

b)

0b11111

c)

0b11110

d)

0b11100

129.

What will be the output of the following print statements?

a)

False

True

b)

True

True

c)

False

False

d)

True

False

130.

What will be the output when the follownig code is executed?

a)

error

b)

Type Error: object of type 'int' has no len()

c)

4

d)

0

131.

What will be the output of the following print statement?

a)

Hello P

b)

str is a keyword so the assignment isn't valid

c)

Python!

d)

Hello Python!

132.

What is the output of the following code snippet:

a)

Oranges

b)

'Apple', 'Oranges', 'Bananas'

c)

Bananas

d)

error

133.

What will be the output of the following print statement?

a)

3

b)

error

c)

1.,2.3.

d)

'Earth

134.

Which of the following statements is correct?

a)

A tuple cannot be modified once created, as they are immutable by design

b)

Adding tuples will produce a new tuple

c)

The elements in a tuple can be accessed by using their index position

d)

All of these are correct.

135.

What is the result of the following print statement?

a)

['Milk', 'Cheese']

b)

['Bread', 'Butter']

c)

['Milk', 'Cheese', 'Bread', 'Butter']

d)

SyntaxError

136.

What is the result of the following print statement?

a)

"New York"

b)

['London', 'Rome']

c)

["London","New York","Rome"]

d)

SyntaxError

137.

What would be the output of the following code when executed?

a)

{1: 'iOS', 2: 'Android'}

b)

{1: 'iOS', 'Android'}

c)

{'iOS', 'Android'}

d)

{1: 'iOS'}

138.

What will be the output of the following code when executed?

a)

London

Paris

Berlin

b)

UK

France

Germany

c)

('London', 'UK') ('Paris', 'France') ('Berlin', 'Germany')

d)

('UK', 'London') ('France', 'Paris') ('Germany', 'Berlin')

139.

What will be the output of the following code when executed?

a)

hi

b)

SyntaxError

c)

bye

d)

error

140.

Is this the correct way to write the code?

a)

Yes, the syntax is correct.

b)

No, the syntax is incorrect.

141.

What will be the output of the following code when executed?

a)

1

2

3

b)

1

2

3

hi

c)

1

2

d)

1

2

hi

142.

What will be the output of the following code when executed?

a)

1

2

3

hi

b)

1

2

3

c)

1

d)

error

143.

What will be the output of the following code when executed?

a)

Break

b)

1

2

3

4

c)

SyntaxError

d)

1

144.

What will be the output of the following code when executed?

a)

1

2

3

Break

b)

1

2

3

4

Break

c)

Break

d)

1

2

3

4

145.

What is the result of the following code when executed?

a)

20

b)

19

c)

16

146.

What will be the output of the following code when executed?

a)

['a', 'b', 'c', 'c']

b)

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

c)

['a', 'c', 'c', 'd']

d)

SyntaxError

147.

What will be the output of the following code when executed?

a)

Cappuccino', 'Latte', 'Macchiato'

b)

['Tea']

c)

Cappuccino', 'Latte', 'Macchiato', 'tea'

d)

error

148.

What will be the output of the following code when executed?

a)

10

b)

error

c)

24

d)

1

149.

What will be the output of the following code when executed?

a)

Dar es salaam

b)

A', 'A*', 'A+'

c)

Robert

d)

Robert', 'Dar es salaam', ['A', 'A*', 'A+']

150.

What is the output of the following code?

a)

Robert: 29: Dar es salaam

b)

NAME='Robert, AGE=29, CITY='Dar es salaam'

c)

NAME:Robert AGE:29 CITY:Dar es salaam

d)

SyntaxError