Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Worksheet

Total questions: 86

Worksheet time: 43mins

Name
Class
Date
1.

Which of the following variable names is invalid in Python?

a)

def

b)

1st_number

c)

_count

d)

color text

e)

!data

2.

When refactoring the "spaghetti code" into a modular structure, which actions are MANDATORY?

a)

Defining clear interfaces (which functions and with which parameters the module exports).

b)

Ensuring weak connectivity between the created modules.

c)

Separation of logically related functions into separate modules (.py files).

d)

Rename all variables according to the same standard.

3.

Which of the following cases violates the DRY principle?

a)

The discount calculation code is repeated in three places of the program

b)

One function calculates the discount, the other applies the tax

c)

Three different functions for working with different types of products

4.

What is the main difference between for and while loops in Python?

a)

for requires explicit counter indication, while does not.

b)

for can be interrupted using break, but while cannot.

c)

while is always executed at least once, and for may not be executed even once.

5.

How many times will the print(count) instruction be executed?

a)

2

b)

4

c)

бесконечное

d)

5

e)

1

6.

What result will be displayed in the console?

a)

Mistake

b)

Even and less than or equal to 10

c)

Even and greater than 10

d)

Odd

7.

What code should I insert instead of ???

a)

symmetric_difference

b)

union

c)

differenc

d)

intersection

8.

Which version of the Python code sets the condition block correctly?

a)

if x > 0: print("positive")

b)

if x > 0 { print("positive") }

c)

if x > 0 print("positive")

d)

if (x > 0) then print("positive")

9.

What will be displayed in the console?

a)

0

b)

3

c)

5

d)

7

e)

15

10.

Which of these properties is NOT a typical problem of spaghetti code?

a)

Excessive modularity

b)

Unmaintainability

c)

Unreusability

d)

Unintelligibility

e)

Testing difficulty

11.

What do Python code blocks mean (instead of curly braces)?

a)

Indentation (intervals/tabs)

b)

With special characters #BEGIN/#END

c)

In quotation marks

d)

Two dots at the beginning of the block without indentation

12.

What are the advantages of a modular project structure?

a)

A mistake in one module won't break the whole project.

b)

Reuse of modules in other projects

c)

Different people can work on different modules.

d)

The code becomes definitely shorter.

e)

Renaming of all functions can be used.

13.

Advantages of using functions in Python

a)

The functions contribute to compliance with the SRP principle.

b)

Functions allow you to use input parameters and return values.

c)

The functions help to reduce code duplication by following the DRY principle.

d)

Functions always speed up program execution by compiling.

e)

Functions allow you to split the code into named, self-contained fragments.

14.

Which operations with tuples are CORRECT?

a)

a, b, *rest = (1, 2, 3, 4, 5)

b)

coordinates = (lat, lon) = (43.22, 76.85)

c)

x, y = (10, 20)

d)

new_tuple = old_tuple + (6, 7)

e)

my_tuple[0] = 100

15.

What will be displayed in the console?

a)

Unknown team

b)

Uploading user_data

c)

Execution error

16.

Which operations with Counter are CORRECT?

a)

c1 + c2

b)

c1 | c2

c)

c1 - c2

d)

c1 & c2

e)

c1 / c2

17.

What happens when executing this code?

a)

(1, [2, 3, 5], 4)

b)

(1, [2, 3], 4)

c)

(1, [2, 3], 4, 5)

d)

Mistake

18.

Which statements about hash functions are CORRECT?

a)

In Python, hash((1, 2)) == hash((1, 2))

b)

A small change in the input data should cause a significant change in the hash

c)

The hash function should be calculated quickly

d)

The hash function ensures that there are no collisions

19.

MOST LIKELY cause of the error

a)

Incorrect import syntax. To import correctly from a subfolder, use from student_system.student_management import add_student

b)

The SRP principle is violated

c)

There is no add_student function

d)

The DRY principle has not been applied

20.

Specify ALL the advantages of the SRP principle

a)

A function has one responsibility

b)

The code is easier to test

c)

Debugging is simplified

d)

The program execution speed is reduced

e)

No comments needed in the code

21.

What is NOT the purpose of modularity?

a)

Complete exclusion of errors from the program

b)

Code reuse

c)

Error localization

d)

Simplify development by splitting it into parts

22.

Which are advantages of modularity in software development?

a)

Reuse of module code in other projects

b)

Simplify development (different teams can work on different modules)

c)

Information hiding (Encapsulation)

d)

Localization of errors

e)

Improving the execution speed of the entire application

23.

Which statement about the result is INCORRECT?

a)

Key 2 contains the list [2, 4] (the order is guaranteed)

b)

The setdefault() function creates a new list if there is no key.

c)

Key 1 contains the list [1]

d)

Key 3 contains the list [3]

24.

What will be the result of executing the following code? a = 0 for i in range(3): a += 1 if i == 1: break print(a)

a)

Error (syntax error)

b)

(правильного варианта среди чисел нет)

25.

In the try-except-finally block, which block is guaranteed to be executed?

a)

finally

b)

except

c)

None of them

d)

Only try

26.

What function in Python should be used to determine the data type of a variable?

a)

type()

b)

typeof()

c)

datatype()

d)

get_type()

27.

Which of the following cases violates the DRY principle?

a)

The discount calculation code is repeated in three places of the program

b)

Three different functions for working with different types of products

c)

One function calculates the discount, the other applies the tax

28.

Which version of the Python code sets the condition block correctly?

a)

if x > 0: print("positive")

b)

if x > 0 print("positive")

c)

if (x > 0) then print("positive")

d)

if x > 0 { print("positive") }

29.

What will the expression return? re.findall(r'[bA-Za-z]+', 'Hello, hello 123 world!')

a)

['Hello', 'hello', 'world']

b)

['Hello', 'world']

c)

['hello', 'world']

d)

['Hello', 'hello', 'world', '']

30.

Which variable names are invalid in Python?

a)

1st_number

b)

color text

c)

def

d)

my_variable

e)

!data

31.

What do Python code blocks mean (instead of curly braces)?

a)

Indentation (intervals/tabs)

b)

In quotation marks

c)

With special characters #BEGIN/#END

d)

Two dots at the beginning of the block

32.

What command is used to create a new virtual environment named venv?

a)

python -m venv venv

b)

new-env venv

c)

create venv

d)

make-virtual-env venv

33.

Which of the above is true about variables in Python?

a)

Python uses dynamic typing, and the type of a variable is determined at runtime

b)

Variable names are case insensitive

c)

They require an explicit type declaration

d)

They can start with a number

34.

Why does this code cause an error? coordinates = {(1, 2): "Point A", [3, 4]: "Point B"}

a)

The list [3, 4] cannot be a dictionary key because it is mutable and not hashable

b)

You can't mix different types of keys

c)

The tuple (1, 2) cannot be a key

d)

Incorrect dictionary syntax

35.

Which tool is most often used to install third-party Python libraries?

a)

pip

b)

gem

c)

apt-get

d)

npm

36.

Which statement about the result is INCORRECT?

a)

Key 2 contains the list [2, 4] (the order is guaranteed)

b)

The setdefault() function creates a new list if there is no key

c)

Key 1 contains the list [1]

d)

Key 3 contains the list [3]

37.

Advantages of modularity in software development

a)

Localization of errors

b)

Improving the execution speed of the entire application

c)

Simplify development (different teams can work on different modules)

d)

Reuse of module code in other projects

e)

Information hiding (Encapsulation)

38.

Which of the following operations with Counter are CORRECT?

a)

c1 & c2 — intersection (minima)

b)

c1 - c2 — counter subtraction (positive results only)

c)

c1 + c2 — adding counters

d)

c1 | c2 — union (maxima)

e)

c1 / c2 — division of counters

39.

Which of the following operations with tuples are CORRECT?

a)

a, b, *rest = (1, 2, 3, 4, 5)

b)

x, y = (10, 20)

c)

new_tuple = old_tuple + (6, 7)

d)

coordinates = (lat, lon) = (43.22, 76.85)

e)

my_tuple[0] = 100

40.

Which of the statements about hash functions are CORRECT?

a)

In Python, hash((1, 2)) will be equal to hash((1, 2))

b)

A small change in the input data should cause a significant change in the hash

c)

The hash function should be calculated quickly

d)

The hash function ensures that there are no collisions

41.

Какие утверждения описывают преимущества использования функций в Python?

a)

Functions allow you to use input parameters and return values

b)

Functions allow you to split the code into named, self-contained fragments

c)

The functions help to reduce code duplication by following the DRY principle

d)

The functions contribute to compliance with the SRP principle

e)

Functions always speed up program execution

42.

What will be displayed in the console?

a)

Unknown team

b)

Uploading user_data

c)

Execution error

43.

Which situations indicate that code requires refactoring and modularity?

a)

Adding a new feature causes unexpected errors in another module

b)

The function takes up several screens of code

c)

Fixing one error requires changes in multiple files

d)

The same logic is repeated in several functions

e)

The code has been working fine for 2 years

44.

What does a decorator function return?

a)

A new function (wrapper) that calls the original one with additional logic

b)

A list of arguments

c)

The number of calls

d)

A TypeError

e)

A string with the function name

45.

Why check the uniqueness of identifiers in data?

a)

To detect duplicate records or errors in identifier assignment

b)

To speed up sorting

c)

To reduce file size

d)

To convert data to JSON

e)

To add database indexes

46.

What does a property setter do?

a)

Allows controlling and validating values when assigning to an attribute

b)

Creates a copy of the object

c)

Replaces the constructor

d)

Makes the attribute read-only

e)

Deletes the attribute

47.

What is meant by a “large ecosystem of libraries” in Python?

a)

A set of third-party packages for different fields available via package managers

b)

Only built-in libraries

c)

Only scientific and AI packages

d)

A small number of standard modules

48.

What is RAPIDS?

a)

A set of GPU libraries (cuDF, cuML) — analogs of Pandas and Scikit-learn

b)

A logging system

c)

A database connector

d)

A CPU optimization extension

e)

A web framework

49.

Which regex pattern is commonly used to match email addresses?

a)

[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}

b)

[a-z]+@[a-z]{1,}[a-z]

c)

\w+@\w+

d)

e)

email:\s*\S+@\S+

50.

Which regex method removes HTML tags?

a)

re.sub(r'<[^>]+>', '', text)

b)

text.strip()

c)

BeautifulSoup.get_text()

d)

text.replace('<', '')

e)

re.findall()

51.

When is it better to use Composition instead of Inheritance?

a)

When an object has another functionality but is not it (Car has an Engine)

b)

When using multiple inheritance

c)

When a class is a specialization of another

d)

When polymorphism is required

e)

When forcing method override

52.

Which construct is used to check Method Resolution Order (MRO)?

a)

D.mro()

b)

D.__mro__

c)

dir(D)

d)

print(D.resolution_order)

53.

Which statement best describes the difference between a class and an object?

a)

A class describes structure and behavior, an object is a concrete instance with data

b)

A class is only for built-in types

c)

A class exists only at runtime

d)

A class and an object are the same

e)

An object describes structure, and a class stores data

54.

What does the broadcasting mechanism do in NumPy?

a)

Creates random matrices from scratch

b)

Converts data from Pandas to NumPy

c)

Removes duplicate elements in an array

d)

Copies arrays to another memory space

55.

Why are the attributes __username and __password made private?

a)

To protect data and control access through methods

b)

To make them inaccessible inside the class

c)

To prevent instances from being created

d)

To make the class abstract

e)

So that Python automatically encrypts the strings

56.

What happens when creating an instance of an abstract class Shape(ABC)?

a)

A TypeError occurs because an instance of an abstract class cannot be created

b)

__init__ from object is called

c)

The pass implementation is used

d)

Python creates implementations automatically

e)

area() is called by default

57.

What is the purpose of the self parameter?

a)

It is a reference to the current instance of the class inside the method

b)

A global variable

c)

A list of all objects

d)

A reserved word denoting the module

e)

Always contains the class name as a string

58.

How to access Dog.species from object my_dog?

a)

my_dog.species

b)

getattr("my_dog", "species")

c)

species.my_dog

d)

my_dog["species"]

e)

Dog(my_dog).species

59.

When is the __init__ method called?

a)

When creating a new object of the class

b)

When the program finishes

c)

When importing the module

d)

When any method is called

e)

When the object is deleted

60.

What is __str__ most often used for?

a)

To define a clear string representation of an object when calling print(obj)

b)

Save object to JSON

c)

Compare objects

d)

Create a copy

e)

Calculate length

61.

What is a fixture in testing?

a)

Prepared data or objects that are passed into tests

b)

Debugging tool

c)

Test report

d)

Decorator for skipping tests

e)

pytest configuration file

62.

How to group data in Pandas and calculate the mean?

a)

df.groupby('group').mean()

b)

pd.mean(df['group'])

c)

df.sort('group').avg()

d)

df.group('group').avg()

e)

df.aggregate('group', 'mean')

63.

What is the time module used for in decorators?

a)

To measure the execution time of a function

b)

To schedule tasks

c)

To work with time zones

d)

To format dates

e)

To synchronize threads

64.

What does the @pytest.fixture decorator do?

a)

Creates reusable test data or objects for tests

b)

Disables error output

c)

Runs tests in parallel

d)

Measures execution time

e)

Skips tests

65.

Which library is designed for lemmatizing Russian words?

a)

pymorphy2

b)

BeautifulSoup

c)

requests

d)

re

e)

nltk

66.

How is a private attribute conventionally denoted in Python?

a)

UPPERCASE

b)

In quotes

c)

One underscore

d)

Ends with _private

67.

Which code creates a pie chart in Matplotlib?

a)

plt.piechart(...)

b)

plt.circle(...)

c)

plt.plotpie(...)

d)

plt.bar(...)

68.

What is object-oriented programming (OOP)?

a)

A paradigm where programs are built around objects combining data and behavior

b)

CPU optimization method

c)

Programming language

d)

Standard libraries

e)

Only functions without data

69.

Which pytest flag enables verbose output?

a)

-v

b)

-k

c)

-x

d)

-q

e)

-s

70.

What does plt.plot([1,2,3,4], [1,4,2,3]) do?

a)

Plots a line chart

b)

Displays a histogram

c)

Creates a bar chart

d)

Plots a heatmap

e)

Forms a pie chart

71.

What is a library in Python?

a)

A collection of pre-written code (functions, classes, objects) for specific tasks

b)

Variable storage

c)

Interpreter module

d)

GUI

e)

Installation folder

72.

Which library is the foundation of numerical computing in Python?

a)

NumPy

b)

Pandas

c)

TensorFlow

d)

Requests

e)

Matplotlib

73.

Which method reads the entire file into one string?

a)

f.read()

b)

f.tell()

c)

f.readlines()

d)

f.readline()

e)

f.seek(0)

74.

What is the general message from the lecture: “Using GPU is not magic”?

a)

It is an outdated technology

b)

GPU is only suitable for gaming

c)

It is a marketing slogan

d)

It is an experimental approach

75.

What is the main goal of encapsulation in OOP?

a)

Hiding internal implementation and protecting data

b)

Providing a simple interface

c)

Using attributes with a single underscore

d)

Creating a class hierarchy

e)

Ensuring polymorphic behavior

76.

Which class name corresponds to Python conventions (PEP 8)?

a)

UserProfil

b)

user-Profile

c)

userprofile

d)

USER_PROFILE

e)

user_profile

77.

What are object methods?

a)

Functions defined inside a class that describe the behavior of an object

b)

Any functions in a module

c)

Only built-in functions

d)

OS constructors

e)

Special variables

78.

Which OOP property allows working with objects of different classes through a unified interface?

a)

Polymorphism

b)

Encapsulation

c)

Composition

d)

Abstraction

e)

Inheritance

79.

What is an object (instance of a class)?

a)

A specific instance created from a class

b)

A class description

c)

Only an integer or string

d)

Any Python module

e)

Program file name

80.

What does inheritance do in class Dog(Animal):?

a)

Dog receives all methods and attributes of Animal

b)

Dog cannot add its own methods

c)

Dog deletes Animal’s methods

d)

Dog turns Animal into an abstract class

e)

Dog is no longer an object

81.

What is the pytest module used for?

a)

Writing and running automated tests

b)

Web applications

c)

Data visualization

d)

Asynchronous programming

e)

Databases

82.

Which import is the correct alias for NumPy?

a)

import numpy as np

b)

import numpy.all

c)

import numpy as num

d)

import np as numpy

e)

from numpy import base

83.

What is the main purpose of virtual environments in Python?

a)

Isolation of libraries for different projects

b)

Automatic code formatting

c)

Project file management

d)

Speeding up execution

84.

What will be displayed in the console?

a)

Operation successful Completion.

b)

Division by zero!

c)

Only "Completion."

85.

What does checking the range of values in data mean?

a)

That values fall within acceptable limits (e.g., age from 18 to 120)

b)

Data is sorted

c)

File size is limited

d)

All values are the same

e)

Column contains only text

86.

What does data validation for missing values check?

a)

That there are no empty values (NaN, None) in specified columns

b)

That data is encrypted

c)

That the file is CSV

d)

That strings are sorted

e)

That all numbers are positive