wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PP Final

Total questions: 115

Worksheet time: 58mins

Name
Class
Date
1.

What will be the output of the following Python code?

d = {0: 'a', 1: 'b', 2: 'c'}

for x in d.values():

print(x)

a)

0 1 2

b)

a b c

c)

0 a 1 b 2 c

d)

none of the mentioned

2.

What will be the output of the following Python code?

a="hello"

b=list(x.upper() for x in a)

print(b)

a)

['H', 'E', 'L', 'L', 'O' ]

b)

[('HELLO', 5)]

c)

[('H', 5), ('E', 5), ('L', 5), ('L', 5), ('O', 5)]

d)

Syntax error

3.

What will be the output of the following Python code?

import random

print (random.choice([10.4, 56.99, 76]))

a)

Error

b)

Either 10.4, 56.99 or 76

c)

Any number other than 10.4, 56.99 and 76

d)

56.99 only

4.

What will be the output of the following Python code snippet?

d = {"john":40, "peter":45}

print(list(d.keys()))

a)

["john", "peter"]

b)

["john": 40, "peter": 45]

c)

{"john", "peter"}

d)

("john": 40, "peter": 45)

5.

5. What will be the output of the following Python code snippet?

total = {}

def insert(item):

if item in total:

total[item] += 1

else:

total[item] = 1

insert('Apple')

insert('Ball')insert('Apple')

print(len(total))

a)

3

b)

1

c)

2

d)

0

6.

What will be the output of the following code snippet ?

numbers = [1, 2, 3, 4, 5]

squared_numbers = list(map(lambda x: x**2, numbers))

print(squared_numbers)

a)

[1, 2, 3, 4, 5]

b)

[1, 4, 9, 16, 25]

c)

[2, 4, 6, 8, 10]

d)

[0, 1, 4, 9, 16]

7.

What is the following statements about lambda functions is correct ?

a)

Lambda functions can contain multiple expressions separated by commas

b)

Lambda functions can have named parameters

c)

Lambda functions can contain loops and conditional statements

d)

Lambda functions are limited to a single expression

8.

What does the following Python code accomplish ?

class Car:

def init(self, brand, model):

self.brand = brand

self.model = model

car1 = Car("Toyota", "Camry")

car2 = Car("Ford", "Mustang")

a)

Declares a function

b)

Defines a class named Car with attributes brand and model

c)

Creates a list of cars

d)

Calls a method

9.

What is the purpose of the init method in a Python class ?

a)

To create a new object

b)

To initialize the class attributes

c)

To delete an object

d)

To define a class method

10.

What is the purpose of the self parameter in Python class methods ?

a)

It refers to the class itself

b)

It refers to the object instance of the class

c)

It is a reserved keyword and has no specific purpose

d)

It refers to the parent class

11.

What does the regex pattern \d{2,4} match in Python?

a)

Matches exactly 2 digits

b)

Matches 2 to 4 digits

c)

Matches at least 4 digits

d)

Matches any digit

12.

Which regex pattern will match the end of a string in Python?

a)

$

b)

\$

c)

\d$

d)

\E

13.

In Python regex, what does the expression \B represent?

a)

Backspace character

b)

Non-word boundary

c)

Match a backslash character

d)

Match any whitespace character

14.

What does the '*' symbol indicate in a regex pattern in Python?

a)

Matches zero or one occurrence of the preceding element

b)

Matches zero or more occurrences of the preceding element

c)

Matches one or more occurrences of the preceding element

d)

Matches exactly one occurrence of the preceding element

15.

Which of the following regex patterns will match a valid email address in Python?

a)

\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b

b)

email@domain

c)

[a-z]+@[0-9]+\.[a-z]{3}

d)

email@.com

16.

Which regex pattern will match a string that starts with "abc" and ends with "xyz" in Python?

a)

^abc$xyz

b)

abc|xyz

c)

abc.*xyz

d)

abc+xyz

17.

In Python regex, what does the expression \d represent?

a)

Match any digit character

b)

Match any non-digit character

c)

Match a literal 'd' character

d)

Match any whitespace character

18.

Which of the following regex patterns will match a string that contains only letters in Python?

a)

\w+

b)

[a-zA-Z]+

c)

\D

d)

\S

19.

What does Pygame primarily focus on?

a)

Web development

b)

Machine learning

c)

Game development

d)

Data analysis

20.

What function is used to initialize Pygame?

a)

pygame.init()

b)

pygame.start()

c)

pygame.setup()

d)

pygame.begin()

21.

How do you fill the entire screen with a color in Pygame?

a)

screen.fill(color)

b)

pygame.fill(color)

c)

pygame.draw.fill(color)

d)

pygame.display.fill(color)

22.

Which method is used to load an image in Pygame?

a)

pygame.load_image()

b)

pygame.image.load()

c)

pygame.load()

d)

pygame.image.load_image()

23.

How do you handle collisions between two rectangles in Pygame?

a)

Using pygame.check_collision()

b)

Using pygame.rect_collision()

c)

Using pygame.rect.colliderect()

d)

Using pygame.collision.detect()

24.

What is the purpose of the pygame.sprite.Sprite class?

a)

Handling audio

b)

Managing game states

c)

Creating game objects

d)

Drawing graphics

25.

Which method is used to get the current mouse position in Pygame?

a)

pygame.mouse.current_position()

b)

pygame.mouse.get_position()

c)

pygame.get_mouse_position()

d)

pygame.current_mouse_position()

26.

What arithmetic operators cannot be used with strings ?

a)

+

b)

*

c)

-

d)

All of the mentioned

27.

What will be the output of the following Python code snippet ?

d = {"john":40, "peter":45}

"john" in d

a)

True

b)

False

c)

None

d)

Error

28.

What does the function re.search do?

a)

matches a pattern at the start of the string

b)

matches a pattern at any position in the string

c)

Any numsuch a function does not existber other than 10.4, 56.99 and 76

d)

none of the mentioned

29.

What does the ‘return’ keyword do in a function ?

a)

Terminates the function

b)

Returns a value from the function

c)

Skips the function

d)

Declares a variable

30.

What will be the output of the following code snippet ?

def multiply(a, b=2): return a * b

result = multiply(5)

print(result)

a)

5

b)

10

c)

2

d)

7

31.

What is a lambda function in Python?

a)

A function that returns multiple values

b)

A function that can accept a variable number of arguments

c)

An anonymous function defined using the keyword ‘lambda’

d)

A function that can call itself

32.

What does the filter() function do with a lambda function as its first argument?

a)

Filters out elements from an iterable based on the lambda function’s result

b)

Adds elements to an iterable based on the lambda function's result

c)

Sorts elements in an iterable based on the lambda function's result

d)

Reverses elements in an iterable based on the lambda function’s result

33.

What is the output of the following code snippet ?

my_function = lambda x: "even" if x % 2 == 0 else "odd"

print(my_function(7))

a)

«even»

b)

«odd»

c)

True

d)

False

34.

What does the character '^' represent in a regex pattern in Py

a)

Matches the end of a string

b)

Matches the start of a string

c)

Matches any character except newline

d)

Matches zero or one occurrence of the preceding element

35.

Which of the following regex patterns will match either "cat" or "dog" in Python ?

a)

(cat|dog)

b)

[catdog]

c)

cat*dog

d)

cat&dog

36.

In Python regex, what does the character '.' represent?

a)

Matches any character except newline

b)

Matches zero or one occurrence of the preceding element

c)

Matches the start of a string

d)

Matches a literal period character

37.

What does the regex pattern \w+ match in Python?

a)

Matches a literal 'w' character followed by a plus sign

b)

Matches one or more word characters

c)

Matches whitespace characters

d)

Matches any character except word characters

38.

In Python regex, what does the expression \s represent?

a)

Match any character except whitespace

b)

Match a literal 's' character

c)

Match any whitespace character

d)

Start of a string

39.

What does the character '|' represent in a regex pattern in Python?

a)

Matches the start of a string

b)

Logical OR, matches either the pattern on the left or the one on the right

c)

Matches any digit character

d)

Matches one or more occurrences of the preceding element

40.

What does the '?' symbol indicate in a regex pattern in Python?

a)

Matches zero or more occurrences of the preceding element

b)

Matches one or zero occurrences of the preceding element

c)

Matches exactly one occurrence of the preceding element

d)

Matches one or more occurrences of the preceding element

41.

Which of the following regex patterns will match a phone number with an optional country code in Python?

a)

\d{10}

b)

\d{1,3}-\d{3}-\d{4}

c)

\+?\d{1,3}-\d{3}-\d{4}

d)

(\d{3}-){2}\d{4}

42.

Which module in Pygame is used for handling keyboard input?

a)

pygame.draw

b)

pygame.event

c)

pygame.image

d)

pygame.sound

43.

In Pygame, what does pygame.display.set_mode() do?

a)

Sets the screen resolution

b)

Creates a game window

c)

Initializes the game loop

d)

Loads an image

44.

What is the purpose of the pygame.time.Clock object?

a)

Handling user input

b)

Managing game objects

c)

Controlling the frame rate

d)

Loading images

45.

What function is used to draw a rectangle in Pygame?

a)

pygame.rect()

b)

pygame.draw.rect()

c)

pygame.draw.rectangle()

d)

pygame.draw_square()

46.

Which event is triggered when the close button of the window is clicked?

a)

pygame.QUIT

b)

pygame.CLOSE

c)

pygame.EXIT

d)

pygame.CLOSE_WINDOW

47.

How do you play a sound file in Pygame?

48.

How do you rotate an image in Pygame?

a)

pygame.rotate()

b)

pygame.image.rotate()

c)

pygame.transform.rotate()

d)

pygame.rotate_image()

49.

Where is the variable created correctly?

* We are asking about an answer option that will not give an error

when starting the project *

a)

int num = 2

b)

No suitable option

c)

num = float(2)

d)

var num = 2

e)

$num = 2

50.

What will be the result of this code?

x = 23

num = 0 if x > 10 else 11

print(num)

a)

0

b)

23

c)

10

d)

11

e)

error

51.

What will this code show?

for j in 'Hi! I\'m mister Robert':

if j == '\'': print("Found")

break

else: \

print ("Done")

a)

An error in the code

b)

"Found" and "Done"

c)

Found

d)

Done

52.

How many libraries can be imported into one project?

a)

No more than 3

b)

Unlimited amount

c)

No more than 10

d)

No more than 5

53.

Which library is responsible for the time?

a)

time

b)

localtime

c)

clock

d)

Time

54.

Which function prints something to the console?

a)

write()

b)

log()

c)

out()

d)

print()

55.

What will be shown as a result?

name = "John"

print('Hi, %s' % name)

a)

"Hi, name"

b)

"Hi, "

c)

"Hi, John"

d)

Error

56.

How to get data from user?

a)

Use the input() method

b)

Use the get() method

c)

Use the cin() method

d)

Use the read() method

57.

What are the errors in the code below?

def factorial(n):

if n == 0:

return 1

else: return n * factorial(n - 1)

print(factorial(5))

a)

A function cannot call itself

b)

Return type must be specified

c)

The function will always return 1

d)

Identation error

58.

What will this code show?

for i in range(5):

if i % 2 == 0:

continue

print(i)

a)

Error because i is not assigned

b)

Error due to invalid output

c)

Numbers: 1 and 3

d)

Numbers: 1, 3 and 5

e)

Numbers: 0, 2 and 4

59.

a = 3

for i in range(4):

a += a

Will there be an answer?

a)

48

b)

52

c)

12

d)

96

60.

The while loop is called:

a)

There is no correct answer

b)

Loop with postcondition

c)

Loop with precondition

d)

Loop with parameter

61.

How many times will the loop run

for k in range(7,12):

a)

4

b)

3

c)

0

d)

5

e)

6

62.

What will be the value of the integer variable "a" after the execution

of this program fragment?

a = 4

for i in range(5):

a += i

a)

14

b)

9

c)

20

d)

10

63.

Сколько раз исполнится цикл:

i=4

while i<10:

i=i+3

a)

4

b)

10

c)

3

d)

2

64.

What is the name of the algorithms containing the repetition

construction?

a)

branching

b)

Cyclic

c)

Линейные

d)

Рекурсивные

65.

There is a tuple of the form T = (4, 2, 3).

Which operation will cause the name T to refer to a tuple (1, 2, 3)?

a)

T[0] = 1

b)

T = (1) + T[1:]

c)

T = (1,) + T[1:]

d)

T.startswith(1)

66.

What is the built-in function enumerate() used in Python for?

a)

For simultaneous iteration over the elements themselves and their indices.

b)

To determine the number of elements in a sequence.

c)

To sort elements by id values.

67.

What will the interpreter output for the following program (Python

version 3.6+)?

def get_name_and_decades(name, age):

print(f"My name is {name} and I'm {age / 10:.5f} decades old.")

get_name_and_decades("Leo", 31)

a)

My name is Leo and I'm 31.00000 decades old.

b)

My name is Leo and I'm 3.1 decades old.

c)

My name is {name} and I'm {age / 10:.5f} decades old.

d)

My name is Leo and I'm 3.10000 decades old.

68.

It is necessary to collect and display all unique words from a line of

advertising text. Which of the following Python data types is the best

fit?

a)

set

b)

list

c)

tuple

d)

array

e)

dict

69.

Recording of animals in the zoo is carried out using the list of

dictionaries below. Which line of code will output a structure sorted in

ascending order of animal ages?

animals = [ {'type': 'penguin', 'name': 'Stephanie', 'age': 8},

{'type': 'elephant', 'name': 'Devon', 'age': 3},

{'type': 'puma', 'name': 'Moe', 'age': 5}, ]

a)

sorted(animals, key='age')

b)

sorted(animals, key=lambda animal: animal['age'])

c)

Neither option is correct, two dictionaries cannot be compared with each other.

d)

sorted(animals)

70.

What will be the output of the following code?

def f(a, pargs, *kargs): print(a, pargs, kargs)

f(1, 2, 3, x=4, y=5)

a)

1, 2, 3, {'x': 4, 'y': 5}

b)

1 (2, 3) {'x': 4, 'y': 5}

c)

An exception will be thrown, after the colon it is necessary to go to a new line

d)

1, 2, 3, 'x=4', 'y=5'

e)

1, 2, 3, 4, 5

71.

How to list methods and attributes of x object?

a)

dir(x)

b)

help(x)

c)

info(x)

d)

?x

72.

What will the following code display?

a, *b, c = [1, 2]

print(a, b, c)

a)

[1] [] [2]

b)

An exception will be thrown: there are fewer elements in the list than variables.

c)

1 0 2

d)

1 [] 2

73.

Logical operator and is denoted by:

a)

and

b)

or

c)

not

d)

xor

74.

What is the output of the following program?

x, y, z = "Orange", 231, "Cherry"

print(x)

a)

Orange

b)

Cherry

c)

Orange 231 Cherry

d)

231

75.

What is the output of the following program?

if 5 > 2:

print("Five is greater than two!")

a)

Five is greater than two!

b)

Five is greater than 2!

c)

5 is greater than two!

d)

5 > 2

76.

Which of the following is NOT a python data type?

a)

int

b)

float

c)

char

d)

bool

e)

str

77.

What is the correct way to declare a variable in Python?

a)

var x = 10

b)

x = 10

c)

x := 10

d)

set x = 10

e)

declare x = 10

78.

Which one is not true about Python?

a)

Variable names are not case-sensitive

b)

String variables can be declared either by using single or double quotes

c)

Boolean represent one of two values: True or False

d)

Variables are containers for storing data values

e)

Comments can be used to prevent execution when testing code

79.

What is the output of the following code?

x = 5

y = 2

result = x // y

print(result)

a)

2.5

b)

2

c)

3

d)

10

e)

7

80.

What is the output of this set union operation?

set_a = {1, 2, 3}

set_b = {3, 4, 5}

set_c = set_a.union(set_b)

print(set_c)

a)

{1, 2, 3, 3, 4, 5}

b)

{1, 2}

c)

{1, 2, 3, 4, 5}

d)

{3}

e)

None of the above

81.

What is the purpose of the return statement in a function?

a)

To return a value from the function to the caller

b)

To terminate the function

c)

To specify the data type of the function output

d)

To print the output of the function

e)

To specify the input of the function

82.

When the else block in the while-else construct is executedProgram ends.

a)

Program ends.

b)

When break is executed

c)

When error is occurred

d)

When while statement becomes false

e)

Each time continue is executed.

83.

Which of the following is an example of a python list?

a)

(1, 2, 3)

b)

{1, 2, 3}

c)

[1, 2, 3]

d)

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

e)

'1, 2, 3'

84.

Which Python feature allows you to create small, anonymous functions?

a)

Python Lambda

b)

Python Classes

c)

Python Inheritance

d)

Python Functions

e)

Python Decorators

85.

What is the primary purpose of the init method in a class?

a)

To initialize class attributes

b)

To define class methods

c)

To create class objects

d)

To perform calculations

e)

To define class properties

86.

What is the purpose of using a lambda function with map in Python?

a)

To convert a list of elements into a dictionary

b)

To filter elements in a list based on a condition.

c)

To apply a function to each element in a list and return a new list.

d)

To reduce a list of elements to a single value

e)

To perform mathematical operations on a list of elements and return a

single value

87.

What is possible return type of function

a)

None

b)

list

c)

function

d)

float

e)

all the above

88.

Which of the following statements is true regarding generators?

a)

Generators can only be used with the for loop.

b)

Generators can be created using the yield keyword.

c)

Generators can only be used to generate numbers.

d)

Generators are used to create infinite loops.

e)

Generators cannot be used to iterate over a collection.

89.

What is the purpose of Python iterators?

a)

To define reusable code with attributes and methods

b)

To generate small, anonymous functions

c)

To provide a way to loop over a collection of items

d)

To handle date and time information

e)

To perform mathematical calculations

90.

What can JSON do in Python?

a)

Exchange and store data

b)

Clear a dataset.

c)

Access and change types

d)

Manage data types.

e)

Visualize an upcoming request.

91.

What is the primary purpose of the "global" keyword?

a)

To define a local variable

b)

To define a global variable

c)

To access a global variable from within a function

d)

To define a new function

e)

To import a module

92.

Which method is used to find all occurrences of a pattern in a string using

regular expressions in Python?

a)

match()

b)

search()

c)

find()

d)

findall()

e)

All the above

93.

Which of the following regex symbols check finite number of

characters

a)

?

b)

{5:}

c)

+

d)

*

e)

{0:}

94.

Which method in python's regex module is used to match a pattern at the start of a

string?

a)

match()

b)

search()

c)

findall()

d)

sub()

e)

split()

95.

In Python regular expressions, what do metacharacters represent?

a)

Special characters that match literal characters

b)

Characters that are used for string formatting

c)

Characters that match any digit

d)

Characters that match any whitespace character

e)

Characters that have special meaning and are used to define the pattern

96.

Which parameter of open() is defined incorrectly?

a)

. "a" - will append to the end of the file

b)

"w" - will overwrite any existing content

c)

"x" - will create a file, returns an error if the file exist

d)

"a" - will return an error if the file does not exist

e)

"w" - will create a file if the specified file does not exist

97.

Which of the following is NOT a Python built-in function?

a)

max()

b)

pow()

c)

random()

d)

len()

e)

all()

98.

What is the correct way to create a file named "example.txt" using open

function?

a)

file = open("example.txt", "r")

b)

file = open("example.txt", "b")

c)

file = open("example.txt", "a")

d)

file = open("example.txt", "rb")

e)

file = open("example.txt", "x")

99.

What you could use to get a list of all lines in a files

a)

readlines()

b)

read()

c)

readline()

d)

read_files()

e)

readlist()

100.

Which pygame function is used to set the size of the window?

a)

pygame.display.set_mode()

b)

pygame.display.set_screen()

c)

pygame.display.set_size()

d)

pygame.transform.scale()

e)

none

101.

Which pygame function is used to load an image from a file and return a Surface

object?

a)

pygame.display.set_mode()

b)

pygame.image.load()

c)

pygame.draw.rect()

d)

pygame.mixer.Sound()

e)

pygame.time.Clock()

102.

How can you play a sound effect in Pygame?

a)

By using the pygame.play_sound() function

b)

By using the pygame.load_sound() function

c)

By using the pygame.sound.play() function

d)

By using the pygame.mixer.play() function

e)

By using the pygame.sound_effect.play() function

103.

The type of event that fires when the user clicks the close button in the corner of the

window in Pygame.

a)

pygame.DIPSLAY

b)

pygame.QUIT

c)

pygame.EXIT()

d)

pygame.LEAVE

e)

pygame.EXIT

104.

Which Pygame module is used for collision detection?

a)

pygame.event

b)

pygame.mixer

c)

pygame.sprite

d)

pygame.font

e)

pygame.image

105.

What is the value returned by pygame.mouse.get_pos() ?

a)

The current position of the mouse cursor

b)

The position of the mouse cursor relative to the center of the screen

c)

The change in position of the mouse cursor since the last frame

d)

The position of the last mouse button click

e)

The position of the mouse cursor relative to a specific sprite

106.

Chose correct order of methods for Centralized Scene Logic

a)

Render, Process, Input

b)

Process, Update, Render

c)

Input, Process, Render

d)

Render, Update, Input

e)

Init, Input, Process

107.

Which of the following is a correct way to handle input in pygame?

a)

Use the built-in "input" function in python to read keyboard input

b)

Use a while loop to continuously check for keyboard input.

c)

Define an event handler function that checks for keyboard events and add it to the

event queue

d)

Use the "keyboard" module from the pygame library to read keyboard input.

e)

Use the "input" method of the pygame "Keyboard" class to read keyboard input

108.

Which Pygame module is used to draw shapes and lines on the screen?

a)

pygame.surface

b)

pygame.paint

c)

pygame.drawing

d)

pygame.draw

e)

pygame.graphic

109.

Draw a green rectangle in Pygame.

a)

pygame.draw.rect(screen, (0,255,0), pygame.Rect(10, 10, 100, 100), 10)

b)

pygame.draw.rect(screen, (0,255,0), Rect(10, 10, 100, 100), 10)

c)

pygame.draw.rect(screen, (0,255,0), pygame.rect(10, 10, 100), 10)

d)

pygame.draw.rect(screen, (0,255,0), pygame.rect(10, 10, 100, 100))

e)

pygame.draw.rect(screen, (0,255,0), pygame.Rect(10, 10, 10, 100, 100))

110.

In a typical platformer game using Pygame, what is the most common method

for handling gravity?

a)

Applying a constant force to the player character

b)

Modifying the player character's position

c)

Detecting collisions with the ground

d)

Using the physics module

e)

All the above

111.

How we can check collision between two objects in pygame? (For example to

determine if Snake object has collided with the Food object in Snake game)

a)

By comparing the x and y coordinates of the Snake object's head to the Food object's

location

b)

By comparing the x and y coordinates of the Snake object's head to the x and y

coordinates of each block of the Snake's body

c)

By using pygame functions to determine collisions

d)

A and C

e)

All the above

112.

Which of the following query depicts the correct Select statement?

a)

SELECT * from data

b)

SELECT all from data

c)

SELECT # from data

d)

Select column from

e)

Select ** from data

113.

Which query add information to table

a)

Create

b)

Insert

c)

Update

d)

Alter

e)

Drop

114.

f What is the purpose of the following SQL command in PostgreSQL?CREATE TABLE mytable (

id SERIAL PRIMARY KEY

, name VARCHAR(50)

, age INT

);

a)

To create a new PostgreSQL database called "mytable"

b)

To create a new schema called "mytable"

c)

To create a new table called "mytable" with columns "id", "name", and "age"

d)

To add a new row to the "mytable" table

e)

To modify the structure of an existing table called "mytable"

115.

Which Python library is commonly used to connect to a PostgreSQL database server?

a)

psycopg2

b)

SQLAlchemy

c)

pyMySQL

d)

Django ORM

e)

Pandas