Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

IT 403 - Quiz 2

Total questions: 25

Worksheet time: 17mins

Name
Class
Date
1.

When importing a module using from module_name import *, it automatically imports all functions, variables, and classes without any namespace conflicts.

a)

True

b)

False

2.

Tuples are immutable, which means you cannot modify individual elements, but you can reassign the entire tuple variable to a new tuple.

a)

True

b)

False

3.

The finally block in exception handling will execute even if a return statement is encountered in the try block.

a)

True

b)

False

4.

When a function parameter has a default value, it must be placed after all parameters without default values in the function definition.

a)

True

b)

False

5.

The __init.py__ file in a Python package is required to make Python treat the directory as a package, and it must contain import statements for all modules in that package.

a)

True

b)

False

6.

Which of the following best explains why tuple unpacking is considered a powerful feature in Python?

a)

It allows tuples to be modified after creation

b)

It enables elegant assignment of multiple variables in a single operation

c)

It automatically converts tuples to lists for easier manipulation

d)

It provides better memory management than individual variable assignments

7.

In the context of variable scope, what happens when a function tries to modify a global variable without using the global keyword?

a)

Python raises a NameError immediately

b)

The function creates a local variable with the same name, leaving the global variable unchanged

c)

The global variable is automatically modified

d)

Python raises a SyntaxError during compilation

8.

Which exception handling approach demonstrates the best practice for managing multiple potential errors?

a)

Using a single except Exception: to catch all possible errors

b)

Using multiple specific except clauses for different error types

c)

Using try-except without specifying exception types

d)

Using only finally blocks without except clauses

9.

What is the primary advantage of using *args and **kwargs in function definitions?

a)

They improve function execution speed

b)

They allow functions to accept a variable number of arguments

c)

They automatically validate input parameters

d)

They enable functions to return multiple values

10.

When using dictionary methods, what is the key difference between .get() and direct key access using square brackets?

a)

.get() is faster for key lookups

b)

.get() returns None for missing keys while square brackets raise KeyError

c)

Square brackets can only access string keys

d)

.get() automatically creates missing keys

11.

What is the primary purpose of the if __name__ == "__main__": construct in Python modules?

a)

To define the main function of the module

b)

To prevent the module from being imported by other scripts

c)

To execute code only when the module is run directly, not when imported

d)

To specify the module's version information

12.

Which import strategy provides the best balance between code readability and namespace management?

a)

from module import * for convenience

b)

import module with full module names for clarity

c)

Using aliases with import module as alias for commonly used modules

d)

Selective imports with from module import specific_function

13.

In Python package structure, what role does the __init.py__ file serve beyond making a directory a package?

a)

It only marks the directory as a package and serves no other purpose

b)

It can control what gets imported when someone imports the package

c)

It automatically imports all modules in the package

d)

It defines the package's main execution entry point

14.

When designing a package hierarchy, what is considered the best practice for organizing related functionality?

a)

Put all functions in a single large module to avoid complexity

b)

Create one module per function for maximum modularity

c)

Group related functions into logically organized modules within packages

d)

Use only built-in modules to avoid dependency issues

15.

What is the main advantage of using a requirements.txt file in Python projects?

a)

It automatically installs Python on new systems

b)

It ensures reproducible environments by specifying exact package versions

c)

It speeds up package installation significantly

d)

It reduces the size of Python packages

16.

Analyze the following code and determine the output:

a)

65

b)

60

c)

165

d)

160

17.

What will be the output of this code fragment?

a)

(1, 3, 5) <class 'tuple'>

b)

[1, 3, 5] <class 'list'>

c)

(1, 2, 3, 4, 5, 6) <class 'tuple'>

d)

[1, 2, 3, 4, 5, 6] <class 'list'>

18.

Trace through this exception handling code:

a)

Calculation attempted

Cannot divide by zero

b)

Cannot divide by zero

c)

Calculation attempted

None

d)

Calculation attempted

Invalid input type

19.

What is the output of this dictionary manipulation code?

a)

4, -2

b)

3, Not found

c)

4, Not found

d)

3, -2

20.
  1. Analyze this scope-related code:

a)

Global: 8, Local: 0

b)

Global: 3, Local: 0

c)

Global: 0, Local: 0

d)

Global: 0, Local: 3

21.
a)

def, return

b)

function, print

c)

def, print

d)

func, return

22.
a)

try, except

b)

if, else

c)

try, catch

d)

check, error

23.
a)

0, -1, len

b)

1, 4, size

c)

0, 3, length

d)

1, -1, len

24.
a)

*, +, final_grade

b)

**, *, total

c)

/, +, final_grade

d)

=, +, final_grade

25.
a)

age, student, major

b)

years, student, course

c)

age, ("Alice", 20, "BSIT"), major

d)

old, student, major