Font size
Worksheetsict 2023 python
Total questions: 119
Worksheet time: 3585secs
What was Python named after?
A type of snake
A British comedy show
A famous programming pioneer
A famous scientist
What is the significance of libraries like Pandas, TensorFlow, and Scikit-learn in Python?
They are used for creating video games.
They are used for web development.
They are used for data analysis and machine learning.
They are used for scientific computing.
How is Python described in the introduction?
A bridge connecting thought to action
A highly complex programming language
A language that prioritizes brevity over readability
A language with limited capabilities
Which of the following is NOT an advantage of Python?
Readability
Versatility
Speed
Community support
Who implemented Python in December 1989?
Bill Gates
Linus Torvalds
Guido van Rossum
Tim Berners-Lee
In Python, which data type is used to store a sequence of characters?
Float
String
Integer
Boolean
What does the len() function in Python do?
Converts a string to lowercase
Returns the length of a list or string
Converts a number to a string
Rounds a floating-point number
Which operator is used to check if two values are equal in Python?
=
==
!=
<>
.In Python, which of the following is a valid way to comment multiple lines of code?
/* This is a comment */
// This is a comment //
''' This is a comment '''
# This is a comment
What is the output of the following code? x = 5 y = 2 result = x // y print(result)
2.5
2
2.0
2.25
What arithmetic operators cannot be used with strings ?
+
*
–
All of the mentioned
What will be the output of the following Python code snippet ?
d = {"john":40, "peter":45}
"john" in d
True
False
None
Error
What will be the output of the following Python code ?
random.choice([10.4, 56.99, 76])
Error
Either 10.4, 56.99 or 76
Any number other than 10.4, 56.99 and 76
56.99 only
What does the function re.search do?
matches a pattern at the start of the string
matches a pattern at any position in the string
such a function does not exist
none of the mentioned
What will be the output of the following Python code snippet ?
d = {"john":40, "peter":45}
print(list(d.keys()))
["john", "peter"]
["john": 40, "peter": 45]
{"john", "peter"}
("john": 40, "peter": 45)
What does the ‘return’ keyword do in a function ?
Terminates the function
Returns a value from the function
Skips the function
Declares a variable
What will be the output of the following code snippet ?
def multiply(a, b=2):
return a * b
result = multiply(5)
print(result)
5
10
2
7
What is a lambda function in Python?
A function that returns multiple values
A function that can accept a variable number of arguments
An anonymous function defined using the keyword ‘lambda’
A function that can call itself
What does the filter() function do with a lambda function as its first argument?
Filters out elements from an iterable based on the lambda function’s result
Adds elements to an iterable based on the lambda function's result
Sorts elements in an iterable based on the lambda function's result
Reverses elements in an iterable based on the lambda function’s result
What is the output of the following code snippet ?
my_function = lambda x: "even" if x % 2 == 0 else "odd"
print(my_function(7))
«even»
«odd»
True
False
What does the character '^' represent in a regex pattern in Python ?
Matches the end of a string
Matches the start of a string
Matches any character except newline
Matches zero or one occurrence of the preceding element
Which of the following regex patterns will match either "cat" or "dog" in Python ?
(cat|dog)
[catdog]
cat*dog
cat&dog
In Python regex, what does the character '.' represent?
Matches any character except newline
Matches zero or one occurrence of the preceding element
Matches the start of a string
Matches a literal period character
What does the regex pattern \w+ match in Python?
Matches a literal 'w' character followed by a plus sign
Matches one or more word characters
Matches whitespace characters
Matches any character except word characters
In Python regex, what does the expression \s represent?
Match any character except whitespace
Match a literal 's' character
Match any whitespace character
Start of a string
What does the character '|' represent in a regex pattern in Python?
Logical OR, matches either the pattern on the left or the one on the right
Matches the start of a string
Matches any digit character
Matches one or more occurrences of the preceding element
What does the '?' symbol indicate in a regex pattern in Python?
Matches zero or more occurrences of the preceding element
Matches one or zero occurrences of the preceding element
Matches exactly one occurrence of the preceding element
Matches one or more occurrences of the preceding element
Which of the following regex patterns will match a phone number with an optional country code in Python?
\d{10}
\d{1,3}-\d{3}-\d{4}
\+?\d{1,3}-\d{3}-\d{4}
(\d{3}-){2}\d{4}
Which module in Pygame is used for handling keyboard input?
pygame.draw
pygame.event
pygame.image
pygame.sound
In Pygame, what does pygame.display.set_mode() do?
Sets the screen resolution
Creates a game window
Initializes the game loop
Loads an image
What is the purpose of the pygame.time.Clock object?
Handling user input
Managing game objects
Controlling the frame rate
Loading images
What function is used to draw a rectangle in Pygame?
pygame.rect()
pygame.draw.rectangle()
pygame.draw.rect()
pygame.draw_square()
Which event is triggered when the close button of the window is clicked?
pygame.QUIT
pygame.CLOSE
pygame.EXIT
pygame.CLOSE_WINDOW
How do you play a sound file in Pygame?
pygame.play_sound()
pygame.sound.play()
pygame.mixer.play()
pygame.audio.play()
How do you rotate an image in Pygame?
pygame.rotate()
pygame.image.rotate()
pygame.transform.rotate()
pygame.rotate_image()
What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.values():
print(x)
0 1 2
a b c
0 a 1 b 2 c
none of the mentioned
What will be the output of the following Python code?a="hello"
b=list(x.upper() for x in a)
print(b)
['H', 'E', 'L', 'L', 'O' ]
[('HELLO', 5)]
[('H', 5), ('E', 5), ('L', 5), ('L', 5), ('O', 5)]
Syntax error
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))
0
1
2
3
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)
[1, 2, 3, 4, 5]
[1, 4, 9, 16, 25]
[2, 4, 6, 8, 10]
[0, 1, 4, 9, 16]
What is the following statements about lambda functions is correct ?
Lambda functions can contain multiple expressions separated by commas
Lambda functions can have named parameters
Lambda functions can contain loops and conditional statements
Lambda functions are limited to a single expression
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")
Declares a function
Defines a class named Car with attributes brand and model
Creates a list of cars
Calls a method
What is the purpose of the init method in a Python class ?
To create a new object
To initialize the class attributes
To delete an object
To define a class method
What is the purpose of the self parameter in Python class methods ?
It refers to the class itself
It refers to the object instance of the class
It is a reserved keyword and has no specific purpose
It refers to the parent class
What does the regex pattern \d{2,4} match in Python?
Matches exactly 2 digits
Matches 2 to 4 digits
Matches at least 4 digits
Matches any digit
Which regex pattern will match the end of a string in Python?
$
\$
\d$
\E
In Python regex, what does the expression \B represent?
Backspace character
Non-word boundary
Match a backslash character
Match any whitespace character
What does the '*' symbol indicate in a regex pattern in Python?
Matches zero or one occurrence of the preceding element
Matches zero or more occurrences of the preceding element
Matches one or more occurrences of the preceding element
Matches exactly one occurrence of the preceding element
Which of the following regex patterns will match a valid email address in Python?
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b
email@domain
[a-z]+@[0-9]+\.[a-z]{3}
email@.com
Which regex pattern will match a string that starts with "abc" and ends with "xyz" in Python?
^abc$xyz
abc.*xyz
abc|xyz
abc+xyz
In Python regex, what does the expression \d represent?
Match any digit character
Match any non-digit character
Match a literal 'd' character
Match any whitespace character
Which of the following regex patterns will match a string that contains only letters in Python?
\w+
[a-zA-Z]+
\D
\S
What does Pygame primarily focus on?
Web development
Machine learning
Game development
Data analysis
What function is used to initialize Pygame?
pygame.init()
pygame.start()
pygame.setup()
pygame.begin()
How do you fill the entire screen with a color in Pygame?
screen.fill(color)
pygame.fill(color)
pygame.draw.fill(color)
pygame.display.fill(color)
Which method is used to load an image in Pygame?
pygame.load_image()
pygame.image.load()
pygame.load()
pygame.image.load_image()
How do you handle collisions between two rectangles in Pygame?
Using pygame.check_collision()
Using pygame.rect_collision()
Using pygame.rect.colliderect()
Using pygame.collision.detect()
What is the purpose of the pygame.sprite.Sprite class?
Handling audio
Managing game states
Creating game objects
Drawing graphics
Which method is used to get the current mouse position in Pygame?
pygame.mouse.current_position()
pygame.mouse.get_position()
pygame.get_mouse_position()
pygame.current_mouse_position()
Where is the variable created correctly?
* We are asking about an answer option that will not give an error when starting the project *
int num = 2
No suitable option
num = float(2)
var num = 2
$num = 2
What will be the result of this code? x = 23
num = 0 if x > 10 else 11 print(num) *
0
23
10
11
error
What will this code show?
for j in 'Hi! I\'m mister Robert':
if j == '\'': print("Found") break
else: \
print ("Done")
An error in the code
"Found" and "Done"
Found
Done
How many libraries can be imported into one project?
No more than 3
Unlimited amount
No more than 10
No more than 5
Which library is responsible for the time?
localtime
time
clock
Time
Which function prints something to the console?
write()
log()
out()
print()
What will be shown as a result? name = "John"
print('Hi, %s' % name)
"Hi, name"
"Hi, "
"Hi, John"
Error
How to get data from user?
Use the input() method
Use the get() method
Use the cin() method
Use the read() method
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 function cannot call itself
Return type must be specified
The function will always return 1
There are no errors in the code
What will this code show? for i in range(5):
if i % 2 == 0: continue
print(i)
Error because i is not assigned
Error due to invalid output
Numbers: 1 and 3
Numbers: 1, 3 and 5
Numbers: 0, 2 and 4
a = 3
for i in range(4):a += a
Will there be an answer?
48
52
12
96
The while loop is called:
There is no correct answer
Loop with postcondition
Loop with precondition
Loop with parameter
How many times will the loop run
for k in range(7,12):
4
3
0
5
6
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
14
9
20
10
How many times will the loop be executed: i=4
while i<10:
i=i+34
10
3
2
What is the name of the algorithms containing the repetition construction?
branching
Cyclic
LinearRecursiveThere 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)?
T[0] = 1
T = (1) + T[1:]
T = (1,) + T[1:]
T.startswith(1)
What is the built-in function enumerate() used in Python for?
For simultaneous iteration over the elements themselves and their indices.
To determine the number of elements in a sequence.
To sort elements by id values.
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)
My name is Leo and I'm 31.00000 decades old.
My name is Leo and I'm 3.1 decades old.
My name is {name} and I'm {age / 10:.5f} decades old.
My name is Leo and I'm 3.10000 decades old.
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?
set
list
tuple
array
dict
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}, ]
sorted(animals, key='age')
sorted(animals, key=lambda animal: animal['age'])
sorted(animals)
Neither option is correct, two dictionaries cannot be compared with each other.
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)
1, 2, 3, {'x': 4, 'y': 5}
1 (2, 3) {'x': 4, 'y': 5}
An exception will be thrown, after the colon it is necessary to go to a new line.
1, 2, 3, 'x=4', 'y=5'
1, 2, 3, 4, 5
How to list methods and attributes of x object?
dir(x)
help(x)
info(x)
?x
What will the following code display? a, b, c = [1, 2]
print(a, b, c)
[1] [] [2]
An exception will be thrown: there are fewer elements in the list than variables.
1 0 2
1 [] 2
When declaring a class using the class statement, what is written in parentheses after the class name?
The names of the arguments accepted by the init method.
The names of the arguments accepted by the class.
The names of the arguments accepted by the class.
Names of classes generated by this class.
Which of the following is NOT a python data type?
int
float
char
bool
str
What is the correct way to declare a variable in Python?
var x = 10
x = 10
x := 10
set x = 10
declare x = 10
Which one is not true about Python?
Variable names are not case-sensitive
String variables can be declared either by using single or double quotes
Boolean represent one of two values: True or False
Variables are containers for storing data values
Comments can be used to prevent execution when testing code
What is the output of the following code? x=5
y=2
result = x // y print(result)
2.5
2
3
7
10
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)
{1, 2, 3, 3, 4, 5}
{1, 2}
{1, 2, 3, 4, 5}
{3}
None of the above
What is the purpose of the return statement in a function?
To return a value from the function to the caller
To terminate the function
To specify the data type of the function output
To print the output of the function
To specify the input of the function
When the else block in the while-else construct is executed
Program ends.
When break is executed
When error is occurred
When while statement becomes false
Each time continue is executed.
Which of the following is an example of a python list?
(1, 2, 3)
{1, 2, 3}
[1, 2, 3]
{1: 'one', 2: 'two', 3: 'three'}
'1, 2, 3'
Which Python feature allows you to create small, anonymous functions?
Python Lambda
Python Classes
Python Inheritance
Python Functions
Python Decorators
What is the primary purpose of the init method in a class?
To initialize class attributes
To define class methods
To create class objects
To perform calculations
To define class properties
What is the purpose of using a lambda function with map in Python?
To convert a list of elements into a dictionary
To filter elements in a list based on a condition.
To apply a function to each element in a list and return a new list.
To reduce a list of elements to a single value
To perform mathematical operations on a list of elements and return a
single value
The possible return types of a function in Python can include:
None
list
function
float
all the above
Which of the following statements is true regarding generators?
Generators can only be used with the for loop.
Generators can be created using the yield keyword.
Generators can only be used to generate numbers.
Generators are used to create infinite loops.
Generators cannot be used to iterate over a collection.
What is the purpose of Python iterators?
To define reusable code with attributes and methods
To generate small, anonymous functions
To provide a way to loop over a collection of items
To handle date and time information
To perform mathematical calculations
What can JSON do in Python?
Exchange and store data
Clear a dataset.
Access and change types
Manage data types.
Visualize an upcoming request.
What is the primary purpose of the "global" keyword?
To define a local variable
To define a global variable
To access a global variable from within a function
To define a new function
To define a new function
Which method is used to find all occurrences of a pattern in a string using regular expressions in Python?
match()
search()
find()
findall()
All the above
Which of the following regex symbols check finite number of characters
?
{5:}
+
*
{0:}
Which method in python's regex module is used to match a pattern at the start of a string?
match()
search()
findall()
sub()
split()
Python regular expressions, what do metacharacters represent?
Special characters that match literal characters
Characters that are used for string formatting
Characters that match any digit
Characters that match any whitespace character
Characters that have special meaning and are used to define the pattern
Which parameter of open() is defined incorrectly?
"a" - will append to the end of the file
"w" - will overwrite any existing content
"x" - will create a file, returns an error if the file exist
"a" - will return an error if the file does not exist
"w" - will create a file if the specified file does not exist
Which of the following is NOT a Python built-in function?
max()
pow()
random()
len()
all()
What is the correct way to create a file named "example.txt" using open function?
file = open("example.txt", "r")
file = open("example.txt", "b")
file = open("example.txt", "a")
file = open("example.txt", "rb")
file = open("example.txt", "x")
What you could use to get a list of all lines in a files
readlines()
read()
readline()
read_files()
readlist()
Which pygame function is used to set the size of the window?
pygame.display.set_mode()
pygame.display.set_screen()
pygame.transform.scale()
pygame.display.set_size()
none
What is the value returned by pygame.mouse.get_pos()
The current position of the mouse cursor
The position of the mouse cursor relative to the center of the screen
The change in position of the mouse cursor since the last frame
The position of the last mouse button click
The position of the mouse cursor relative to a specific sprite
Which Pygame module is used for collision detection?
pygame.event
pygame.mixer
pygame.sprite
pygame.font
pygame.image
Chose correct order of methods for Centralized Scene Logic
Render, Process, Input
Process, Update, Render
Input, Process, Render
Render, Update, Input
Init, Input, Process
Which of the following is a correct way to handle input in pygame?
Use the built-in "input" function in python to read keyboard input.
Use a while loop to continuously check for keyboard input.
Define an event handler function that checks for keyboard events and add it to the
event queue
Use the "keyboard" module from the pygame library to read keyboard input.
Use the "input" method of the pygame "Keyboard" class to read keyboard input
Which Pygame module is used to draw shapes and lines on the screen?
pygame.surface
pygame.paint
pygame.drawing
pygame.draw
pygame.graphic
Draw a green rectangle in Pygame.
pygame.draw.rect(screen, (0,255,0), pygame.Rect(10, 10, 100, 100), 10)
pygame.draw.rect(screen, (0,255,0), Rect(10, 10, 100, 100), 10)
pygame.draw.rect(screen, (0,255,0), pygame.rect(10, 10, 100), 10)
pygame.draw.rect(screen, (0,255,0), pygame.rect(10, 10, 100, 100))
pygame.draw.rect(screen, (0,255,0), pygame.Rect(10, 10, 10, 100, 100))
In a typical platformer game using Pygame, what is the most common method
for handling gravity?
Applying a constant force to the player character
Modifying the player character's position
Detecting collisions with the ground
Using the physics module
All the above
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)
By comparing the x and y coordinates of the Snake object's head to the Food object's location
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
By using pygame functions to determine collisions
A and C
All the above
Which of the following query depicts the correct Select statement?
SELECT * from data
SELECTallfromdata
SELECT # from data
Select column from
Select ** from data
Which query add information to table
Create
Insert
Update
Alter
Drop
f What is the purpose of the following SQL command in PostgreSQL?CREATE TABLE mytable ( id SERIAL PRIMARY KEY
, name VARCHAR(50)
, age INT );
To create a new schema called "mytable"
To create a new PostgreSQL database called "mytable"
To create a new table called "mytable" with columns "id", "name", and "age"
To add a new row to the "mytable" table
To modify the structure of an existing table called "mytable"
