Font size
WorksheetsComputer science with python
Total questions: 170
Worksheet time: 1hrs 29mins
Which statement best describes Python indentation in code blocks?
Ignored by the interpreter
Optional for readability only
Required to define block scope
Used only inside functions
In Python, which symbol starts a single-line comment?
# hash symbol
// double slash
/* block marker */
-- dash pair
Which item is a Python keyword rather than an identifier?
sum
data
if
price
What is the correct classification of tokens like int, float, str in Python?
Identifiers for user variables
Data types decided at runtime
Operators for math operations
Literals representing fixed values
Which operator returns the remainder of division in Python?
// floor division
** exponent operator
% modulo operator
/ true division
Which relational expression correctly checks equality in Python?
a = b for equality
a := b for equality
a !== b for equality
a == b for equality
Which statement about input handling is accurate?
print() converts to integers
input() returns a string
print() accepts only strings
input() returns an integer
Choose the correct logical operator set available in Python.
plus minus times
AND OR NOT
&& || !
and or not
Which control structure is best when iterating a known range?
for loop over range
if-elif chained check
while loop with flag
recursive function calls
In a loop, which statement skips the current iteration and continues?
halt
continue
break
stop
Which operation shows that lists are mutable in Python?
Changing an element by index
Accessing a tuple element
Concatenating two strings
Reading a dictionary value
Given s = "Computer". What does s[1:5] return?
"mput"
"puter"
"Comp"
"ompu"
Which method adds an item to the end of a list?
append()
sort()
insert()
pop()
Which statement best describes tuples?
Unordered and immutable
Ordered and immutable
Mutable and faster
Unordered and mutable
In a dictionary, what must be unique?
Items
Indices
Values
Keys
Which method removes and returns the last list item?
remove()
pop()
insert()
split()
Select the correct way to access a dictionary value for key "id".
data["id"]
data.id()
data.gets("id")
data.items["id"]
Which function returns the number of elements in a list?
range()
size()
count()
len()
Which statement defines a reusable block of code in Python?
Use def with a name
Use class with a name
Use lambda with print
Use import with file
What does return do inside a Python function?
Sends a value back
Creates a variable
Prints a message
Stops the program
Which file mode should you use to add new data to the end of an existing text file without deleting its current contents?
rw mode reads and writes together
w mode creates a fresh empty file
r mode opens file for reading only
a mode appends data at file end
A program reads all lines from a file and then closes it. Which function call is responsible for releasing the file resource?
write() outputs to the file
close() releases the resource
read() fetches file contents
open() creates a file handle
You must handle a runtime error from dividing by zero. Which pair of keywords correctly creates the handler block and the error-catching clause?
break and continue pair
import and from pair
else and finally only
try and except together
In an exception flow, which keyword runs regardless of whether an error occurred, typically used to clean up resources?
except handles raised error
try executes guarded code
else runs when no error
finally runs cleanup always
A module named utils.py defines helper functions. How should you bring those into another script?
import utils to access functions
from utils import script file
open(utils) to load module
read() utils for functions
Which statement best distinguishes a class from an object in Python?
Class is blueprint for objects
Object is class code block
Class is single runtime value
Object defines module imports
When creating an object, which special method initializes its attributes at construction time?
__call__() invocation method
__init__() constructor method
__enter__() context manager
__str__() representation text
Which description correctly matches Python being an interpreted language?
Runs only after bytecode linking
Translates to machine code package
Compiled fully ahead of runtime
Executed line by line by interpreter
Choose the accurate difference between list and tuple in Python.
Both mutable and resizable
Tuple mutable, list immutable
Both immutable by default
List mutable, tuple immutable
During loop control, which pair correctly describes exiting the loop versus skipping one iteration?
continue exits loop, break skips
return exits loop, yield skips
else exits loop, pass skips
break exits loop, continue skips
What does the term 'relation' refer to in a relational database model?
A table
A relationship between tables
A row of data
A column of data
Which of the following is a valid relational database key?
Tuple
Attribute
Primary key
Cardinality
What is the meaning of 'degree' in a relational database?
The number of rows in a table
The number of attributes in a relation
The number of tables in a database
The number of keys in a relation
Which key uniquely identifies each tuple in a relational database table?
Foreign key
Candidate key
Primary key
Alternate key
What is the primary difference between a primary key and a candidate key?
A primary key can have multiple values, but a candidate key cannot
A candidate key can be chosen as a primary key, but a primary key cannot be a candidate key
A candidate key uniquely identifies records, but the primary key does not
A primary key is a combination of multiple candidate keys
In a relational database, the cardinality of a relation refers to:
The number of tuples in a relation
The number of attributes in a relation
The number of foreign keys
The number of columns in a table
What is the domain of an attribute in a relational database model?
The range of values an attribute can take
The name of the attribute
The number of unique values an attribute can hold
The unique identifier for an attribute
Which of the following is an example of a foreign key?
A key in the 'Orders' table that refers to the 'Customer' table
A key that uniquely identifies a row in the 'Customers' table
A primary key in the 'Orders' table
A key used for internal table indexing
Which statement correctly describes a 'candidate key'?
It is any column that can uniquely identify rows in a table
It is a column that uniquely identifies rows, but it is not the primary key
It is the key used for referencing another table
It is the primary key
Which command is used to display all databases in a MySQL system?
SHOW DATABASES
SHOW TABLES
LIST DATABASES
DISPLAY DATABASES
What is the purpose of the `DROP DATABASE` command?
To delete all rows in a table
To delete a specific table from a database
To delete a database and all its contents
To delete a database connection
Which command is used to remove a table from a database?
REMOVE TABLE
DELETE TABLE
DROP TABLE
ALTER TABLE
What is the purpose of the `ALTER TABLE` command?
To delete a table
To update data in a table
To change the structure of an existing table
To retrieve data from a table
Which SQL clause is used to filter records based on a condition?
HAVING
WHERE
ORDER BY
GROUP BY
Which of the following commands is used to insert data into a table?
UPDATE
INSERT INTO
ADD INTO
INSERT RECORD
Which SQL clause is used to sort the result set in ascending or descending order?
GROUP BY
ORDER BY
HAVING
WHERE
Which SQL statement is used to remove data from a table?
DELETE
DROP
REMOVE
TRUNCATE
Which aggregate function is used to calculate the sum of a numeric column?
COUNT()
SUM()
MAX()
AVG()
Which of the following SQL clauses is used to filter groups of records in the result set?
WHERE
HAVING
ORDER BY
GROUP BY
Which of the following is NOT an SQL operator?
AND
OR
SELECT
NOT
Which type of join returns all records when there is a match in one of the tables?
Inner join
Left join
Right join
Outer join
Which type of join returns all records from the right table and the matched records from the left table?
Inner join
Left join
Right join
Full outer join
Which of the following SQL commands will give the Cartesian product of two tables?
SELECT FROM table1, table2
SELECT FROM table1 INNER JOIN table2
SELECT FROM table1 LEFT JOIN table2
SELECT FROM table1 RIGHT JOIN table2
What does the `cursor.execute()` function do in Python's `sqlite3` module?
Opens a connection to the database
Executes a SQL query
Fetches all records from the database
Commits the transaction to the database
Which Python function is used to commit changes to the database after an update or insert operation?
`commit()`
`execute()`
`save()`
`flush()`
What is the purpose of the `%s` in the `execute()` method of Python's `sqlite3`?
It formats strings for display purposes
It is used to represent placeholders for parameters in queries
It indicates a SQL query to execute
It closes the database connection
Assertion (A): In SQL, the `INSERT INTO` command can only be used to insert one row at a time into a table. Reasoning (R): The `INSERT INTO` command can be used to insert multiple rows in a single query, by specifying the values for each row within parentheses.
Both the assertion and reasoning are true, and the reasoning correctly explains the assertion.
Both the assertion and reasoning are true, but the reasoning does not correctly explain the assertion.
The assertion is false, but the reasoning is true.
The assertion is true, but the reasoning is false.
What does LAN stand for?
Limited Area Network
Laser Assisted Network
Local Area Network
Local Aerial Network
ABC University has its campus buildings spread out across the city.
Which network is being used?
LAN
WAN
Which field is computer networks originated from?
Government
Military
Media
Police
Computer networks share...
Files
Resources
Software
All of the above
Hubs are more efficient in distributing data packets than Switches?
True
False
What kind of transmission medium is most appropriate to carry data in a computer network that is exposed to electrical interferences?
Unshielded twisted pair
Optical fiber
Coaxial cable
Microwave
The term HTTP stands for?
Hyper terminal tracing program
Hypertext tracing protocol
Hypertext transfer protocol
Hypertext transmit protocol
Expand NIC.
Network Interaction Card
Network internal Card
Network Interface Card
________________ is the box with the set of RJ-45 ports.
Echo Dot
Memory card
Hub/Switch
________________ have a wireless antenna, which increases the communication range of the radio signals.
Routers
Ethernet cables
Gateway
________________ is a computer network that is created for an individual person.
LAN
PAN
WAN
The best example for WAN is ______________.
Local cable network
Campus network
Internet
_________________ is an overall design of a computer network that describes how a computer network is configured and what strategies are being used in it.
Network Topology
Network Style
Network Architecture
A ______________ is a computer that provides services to clients or workstations.
Main Computer
Server/ Central Hub
Service provider
What is the use of Bridge in the network?
To connect LANs
To separate LANs
To control network speed
All of the above
Each IP packet must contain:
Only source address
Only destination address
Source and destination address
Source or destination address
Which of these is not a communication channel?
Satellite
Microwave
Radiowave
Wi-Fi
Which of these is not an example of unguided media?
Optical fibre cable
Radio wave
Bluetooth
Satellite
Device used to connect dissimilar networks
Modem
Gateway
Bridge
Router
................................ isresponsible for handling the address of the destination computerso that each packet is delivered to its proper destination
IP
TP
TCP
MAC
_________ is a dedicated line between the caller and the sender
Packet switching
Circuit switching
Line switching
Message switching
The techniques of switching in which data is fragmented into smaller techniques is called ..............
Circuit switching
Message switching
Packet switching
Line switching
What does a modem do in a network?
Routes data between networks
Converts digital data to analog signals
Amplifies signal strength
Connects devices wirelessly
What is the main function of an Ethernet card?
To provide wireless internet access
To connect devices to a wired network
To amplify network signals
To convert IP addresses
Eesha is setting up her home office and needs to connect her computer to the router. Which type of connector should she use for her Ethernet cable?
RJ11
RJ45
HDMI
VGA
Which network device forwards data to the correct device in a network?
Hub
Switch
Modem
Repeater
Sneha is trying to set up a wireless network in her large house, but she finds that the signal does not reach the farthest rooms. She wonders what device she can use to improve the coverage of her network.
Connect different networks
Extend the range of a network
Route data to the correct device
Encrypt data packets
Which device is used to connect two different networks and routes traffic between them?
Switch
Modem
Router
Hub
What is the role of a gateway in a network?
To connect multiple devices in a network
To connect different networks and route traffic
To amplify the signal
To manage IP addresses
Myra is trying to connect her laptop to the internet at a coffee shop. A WiFi card allows her device to:
Connect via Bluetooth
Connect to wired networks
Connect to wireless networks
Manage the DNS server
Which of the following is NOT a function of a modem?
Converting digital signals to analog signals
Providing wireless connectivity
Allowing internet access over telephone lines
Converting analog signals to digital signals
Which network device is used to extend the range of WiFi signals?
Hub
Switch
Repeater
Router
Which device transmits data to all devices in a LAN, regardless of destination?
Hub
Switch
Repeater
Router
Which device is responsible for translating domain names into IP addresses?
Gateway
DNS server
Router
Switch
Asher is setting up his home network and wants to connect his devices to the internet using a broadband connection. Which of the following can help him achieve that?
Modem
Ethernet card
Switch
Router
What is the primary difference between a hub and a switch?
A switch forwards data to the correct device, while a hub sends it to all devices.
A switch uses wireless technology; a hub does not.
A hub assigns IP addresses, but a switch does not.
A switch is used for longdistance connections, while a hub is used for local connections.
Which of the following is the most common network topology in modern networks?
Bus
Star
Tree
Mesh
In which topology does each device connect to a central point, such as a hub or switch?
Ring
Bus
Star
Mesh
Which network topology is best for large, complex networks where devices are connected in a hierarchical manner?
Star
Tree
Bus
Mesh
What does WAN stand for?
Wide Area Network
Wireless Access Network
Wide Application Network
Web Area Network
Which network type is best suited for connecting devices in a city or campus?
PAN
LAN
MAN
WAN
In which network topology does each device pass data to its immediate neighbor, forming a loop?
Mesh
Ring
Bus
Star
Which of the following is a disadvantage of bus topology?
Easy to install and expand
Single cable failure can bring down the whole network
Devices are directly connected to the hub
Efficient for large networks
A network topology where all devices are connected to a single central cable is known as:
Star topology
Bus topology
Tree topology
Mesh topology
What does a mesh topology allow that other topologies don’t?
Direct devicetodevice communication
All devices to be connected in a single loop
Increased reliability due to redundant connections
Lower installation costs
In which topology is there no central point of failure, since data can be routed in multiple paths?
Ring
Mesh
Star
Bus
Which protocol is used for transferring web pages over the internet?
FTP
HTTP
SMTP
POP3
Which of the following protocols is used for email retrieval from a mail server?
SMTP
FTP
POP3
IMAP
Which protocol is commonly used for sending emails?
FTP
HTTP
SMTP
SSH
What does TCP ensure in a network communication?
Encryption of data
Reliable transmission of data
Faster transmission speed
Secure login credentials
Which protocol is used for secure web communication?
FTP
HTTPS
SMTP
POP3
Which of the following protocols is used for remote login to a server?
Telnet
FTP
HTTP
POP3
What does FTP stand for?
File Transfer Protocol
Fast Transfer Protocol
File Transmission Protocol
Function Transfer Protocol
Which protocol is used for voice communication over the internet?
SMTP
FTP
VoIP
POP3
What is the primary function of the IP protocol?
Transmit files between servers
Route packets of data between devices
Convert digital signals to analog signals
Send emails securely
Which protocol is responsible for establishing a connection between devices over a serial link?
PPP
FTP
TCP/IP
SMTP
What does PPP stand for?
PointtoPoint Protocol
Packet Processing Protocol
Public Protocol Protocol
Pathway Protocol Program
What does the 'WWW' in a web address stand for?
Web Wide World
World Web Workspace
World Wide Web
Wireless Web
Which language is used to describe data in a way that both humans and machines can read it?
HTML
XML
CSS
PHP
A domain name is used to identify:
A server's IP address
A specific webpage within a website
A website's unique name
A website's data
Which of the following is a characteristic of a star topology?
All devices share a single communication line
Each device is connected to a central hub
Data travels in a circular manner
It requires less cabling than bus topology
What is the main purpose of the DHCP protocol?
To assign IP addresses to devices on a network
To encrypt data during transmission
To manage network traffic
To provide a secure connection between networks
Which of the following is a common use of a VPN?
To connect to a local area network
To access the internet securely over a public network
To transfer files between servers
To monitor network performance
Assertion (A): A router connects multiple networks together and routes data between them based on IP addresses.
Reasoning (R): A router operates at the data link layer of the OSI model, which allows it to route packets between devices on different networks.
- a) Both the assertion and reasoning are true, and the reasoning correctly explains the assertion.
- b) Both the assertion and reasoning are true, but the reasoning does not correctly explain the assertion.
- c) The assertion is true, but the reasoning is false.
- d) The assertion is false, but the reasoning is true.
Assertion (A): XML is a markup language that defines the structure of data, making it both human-readable and machine-readable.
Reasoning (R): XML tags are predefined and have specific functions that are universally understood across all platforms.
- a) Both the assertion and reasoning are true, and the reasoning correctly explains the assertion.
- b) Both the assertion and reasoning are true, but the reasoning does not correctly explain the assertion.
- c) The assertion is true, but the reasoning is false.
- d) The assertion is false, but the reasoning is true.
Assertion (A): The HTTP protocol is used to send email messages over the internet.
Reasoning (R): HTTP is designed for communication between web browsers and web servers, while email communication is typically done using SMTP or POP3.
- a) Both the assertion and reasoning are true, and the reasoning correctly explains the assertion.
- b) Both the assertion and reasoning are true, but the reasoning does not correctly explain the assertion.
- c) The assertion is false, but the reasoning is true.
- d) The assertion is true, but the reasoning is false.
Assertion (A): A hub forwards data packets to all devices connected in a network.
Reasoning (R): Since a hub does not differentiate between devices, it broadcasts all data, which can lead to network congestion.
- a) Both the assertion and reasoning are true, and the reasoning correctly explains the assertion.
- b) Both the assertion and reasoning are true, but the reasoning does not correctly explain the assertion.
- c) The assertion is true, but the reasoning is false.
- d) The assertion is false, but the reasoning is true.
SQL is
Structured Query Language
Simple Query Language
Structured Question Language
Structure Quality Language
To remove a record from a table which SQL statement would you use?
Remove
Cancel
Delete
Eradicate
In order to modify data in a database we would use which SQL statement?
Update
Amend
Alter
Modify
Which statement is used to extract data from a database?
Extract
Get
Open
Select
Which statement allows us to add a record to a table?
Add To
Update To
Add Into
Insert Into
Less than or equal to?
>=
=>
=<
<=
Which word is missing from the following SQL statement?
Select * table_name
With
Where
From
And
Which SQL statement would add a record to the database?
INSERT INTO Designer VALUES ('SMI01', 'M Smith', 'mail@msmith.com', '01224123456')
INSERT VALUES ('SMI01', 'M Smith', 'mail@msmith.com', 01224123456') INTO Designer
INSERT ('SMI01', 'M Smith', 'mail@msmith.com', '01224123456') INTO Designer
INSERT Designer INTO VALUES (''SMI01', 'M Smith', 'mail@msmith.com', '01224123456')
Where does the CREATE Command belong?
DML
DDL
DCL
______________ constraint prevents NULL values
UNIQUE
NOT NULL
NULL
FOREIGN KEY
A primary key can be NULL in the table? TRUE or FALSE
TRUE
FALSE
How do we select all rows for the "Designer" table?
SELECT * FROM Designer
SELECT [All] FROM Designer
SELECT Designer.*
SELECT FROM Designer
How would we script a SQL query to select "Description" from the Item table?
SELECT Item.Description
EXTRACT Description FROM Item
SELECT Item FROM Description
SELECT Description FROM Item
How would we script a SQL query to select "Description" from the Item table?
SELECT Item.Description
EXTRACT Description FROM Item
SELECT Item FROM Description
SELECT Description FROM Item
You are required to update the phone number for only the DesignerID "SMI01" in the "Designer" table. Which of these would successfully do that?
UPDATE Designer SET PhoneNo = '01224123456'
UPDATE Designer (PhoneNo) VALUES ('01224123456')
UPDATE Designer SET PhoneNo = '01224123456' WHERE DesignerID = 'SMI01'
UPDATE PhoneNo = '01224123456' FROM Designer WHERE DesignerID = 'SMI01'
How would you DELETE records from the Items table with a "Chair" Type?
DELETE 'Chair' FROM Items
DELETE Type FROM Items WHERE Type = 'Chair'
DELETE FROM Items WHERE Type = 'Chair'
DELETE ITEMS WHERE Type = 'Chair'
With SQL, how do you select all the records from a table named “Persons” where the value of the column “FirstName” ends with an “a”?
SELECT * FROM Persons WHERE FirstName=’a’
SELECT * FROM Persons WHERE FirstName LIKE ‘a%’
SELECT * FROM Persons WHERE FirstName LIKE ‘%a’
SELECT * FROM Persons WHERE FirstName=’%a%’
What does the ALTER TABLE clause do?
The SQL ALTER TABLE clause modifies a table definition by altering, adding, or deleting table columns and/or constraints
The SQL ALTER TABLE clause is used to insert data into database table
THE SQL ALTER TABLE deletes data from database table
The SQL ALTER TABLE clause is used to delete a database table
The UPDATE SQL clause can _____________
update only one row at a time
update more than one row at a time
delete more than one row at a time
delete only one row at a time
How can you change “Hansen” into “Nilsen” in the “LastName” column in the Persons table?
UPDATE Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
MODIFY Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
MODIFY Persons SET LastName=’Hansen’ INTO LastName=’Nilsen’
UPDATE Persons SET LastName=’Nilsen’ WHERE LastName=’Hansen’
Find the names of these cities with temperature and condition whose condition is neither sunny nor cloudy.
SELECT city, temperature, condition FROM weather WHERE condition NOT IN (‘sunny’, ‘cloudy’)
SELECT city, temperature, condition FROM weather WHERE condition NOT BETWEEN (‘sunny’, ‘cloudy’)
SELECT city, temperature, condition FROM weather WHERE condition IN (‘sunny’, ‘cloudy’)
SELECT city, temperature, condition FROM weather WHERE condition BETWEEN (‘sunny’, ‘cloudy’);
Which would find pupils with "er" anywhere in their name?
SELECT * FROM Pupils Where Name = "%er"
SELECT * FROM Pupils Where Name = "$er$"
SELECT * FROM Pupils Where Name = "%er%"
SELECT * FROM Pupils Where Name = "er%"
Which is the correct query to delete the rows of employees whose exp is less than 10.
DELETE * FROM EMP WHERE EXP<10;
DELETE FROM EMP;
DELETE FROM EMP WHERE EXP<10;
DELETE FROM EMP WHERE EXP>10;
Which of the following is not a Constraint in SQL?
Not Null
Unique
Check
Distinct
