wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

LECTURE 06 Quizs(26.11.2025)

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the best way to use code again in a big project?

a)

Write all code in one file

b)

Put code you want to use again in modules and use a script to start the program

c)

Never use modules

d)

Put all code inside `if __name__ == "__main__":`

2.

When you use a Python file in another file, which code does NOT run? (Study tip: Try importing a file with different code blocks and see what happens.)

a)

Code inside any function

b)

Code inside a try...except block

c)

Code inside `if __name__ == "__main__":`

d)

Function definitions

3.

True or False: The main reason for `if __name__ == "__main__":` is to make a main() function.

a)

True

b)

False

4.

True or False: Code inside `if __name__ == "__main__":` only runs when you run the file. (You can test this by putting a print statement inside this block and running/importing the file.)

a)

True

b)

False

5.

What is the value of `__name__` when you run a Python file? (You can add `print(__name__)` to your file and run it in a compiler to check.)

a)

"script"

b)

"__main__"

c)

"module"

d)

"imported"

6.

Why do we use modules in Python?

a)

To make the program slower

b)

To repeat code

c)

To use code again easily

d)

To make more errors

7.

Which one is NOT a step in making software?

a)

Planning

b)

Testing

c)

Importing

d)

Maintenance

8.

Look at this code. What will it print if you run the file? (You can copy and paste this code into a compiler to see what happens.) ```python def greet(): print("Hello!") if __name__ == "__main__": greet() ```

a)

Nothing

b)

Hello!

c)

greet

d)

Error

9.

Which Python feature lets you write code that only runs when the file is run, not when used in another file?

a)

try...except block

b)

`if __name__ == "__main__":` block

c)

for loop

d)

global variable

10.

Which word tells you if a Python file is being run or used in another file? (You can print `__name__` in your file and run it in a compiler to see what it shows.)

a)

\_\_file\_\_

b)

\_\_main\_\_

c)

\_\_name\_\_

d)

\_\_import\_\_

11.

True or False: A Python module is a file you use in another program to use its code. (Study tip: Try making two Python files and use `import` in one to use code from the other.)

a)

True

b)

False

12.

You have a file called `math_utils.py` with a function `add(a, b)`. How do you use this function in another file? (You can try this by making two files and calling the function.)

a)

add(a, b)

b)

import math_utils; math_utils.add(a, b)

c)

include math_utils; add(a, b)

d)

using math_utils.add(a, b)

13.

Why is `if __name__ == "__main__":` useful?

a)

It stops errors

b)

It lets you use code in other files without running main code

c)

It makes the program faster

d)

It makes variables global

14.

How do you use a module named `helper` in Python? (If you want, try making a file called `helper.py` and import it in another file.)

a)

import helper

b)

include helper

c)

using helper

d)

require helper

15.

If you have two files, `main.py` and `helper.py`, and `main.py` uses `helper.py`, what happens to code inside `if __name__ == "__main__":` in `helper.py`? (You can test this by making two files and adding print statements.)

a)

It runs

b)

It is skipped

c)

It causes an error

d)

It becomes a function

16.

You have a file called `toolbox.py`: ```python def tool(): print("Tool used.") if __name__ == "__main__": print("Running as script.") ``` If you use `toolbox` in another file and call `toolbox.tool()`, what will be printed? (You can try this in a compiler to see what happens.)

a)

Tool used.

b)

Running as script.

c)

Tool used. \n Running as script.

d)

Nothing

17.

Pick the code that prints "Application started." only when you run the script. (You can copy and run these code blocks in a compiler to check.)

a)

```python def start_application(): print("Application started.") start_application() ```

b)

```python def start_application(): print("Application started.") if __name__ == "__main__": start_application() ```

c)

```python def start_application(): print("Application started.") if __name__ == "__main__": print("Application started.") ```

d)

```python def start_application(): print("Application started.") ```

18.

True or False: Code reusability means you can use the same code in different programs.

a)

True

b)

False

19.

True or False: A Python script is a file you run to start your program. (This is a study guide: If you are not sure, try making a simple Python file and run it in a compiler.)

a)

True

b)

False

20.

Where should you put a function call if you want it to run only when the file is run?

a)

Inside the function

b)

Inside `if __name__ == "__main__":`

c)

At the top of the file

d)

Outside any block