Module 1: Python Coding Practices and Packaging Concepts
Looking for ‘Developing AI Applications with Python and Flask Module 1 Answers’?
In this post, I provide complete, accurate, and detailed explanations for the answers to Module 1: Python Coding Practices and Packaging Concepts of Course 7: Developing AI Applications with Python and Flask– IBM AI Developer Professional Certificate .
Whether you’re preparing for quizzes or brushing up on your knowledge, these insights will help you master the concepts effectively. Let’s dive into the correct answers and detailed explanations for each question!
Module 1 Practice Quiz: Python Coding Practices and Packaging Concepts
Practice Assignment
1. Identify the file where you add code to reference the modules in the package?
- __init__.py ✅
- __main__.py
- __name__.py
- myproject.py
Explanation:__init__.py
is used to mark a directory as a Python package. This file can contain initialization code for the package or be empty. When you import a package, Python executes the code in __init__.py
.
2. Which of the following is a best practice when creating function names to write test cases?
- _test
- test_ ✅
- Function
- function.test
Explanation:
In Python’s unittest
or pytest
frameworks, test functions should be prefixed with test_
so that the test runner can automatically detect and run them.
3. Which of the following is a valid method name based on PEP8 guidelines?
- GetUserName()
- GET_USER_NAME()
- getUserName()
- get_user_name() ✅
Explanation:
PEP8 recommends using lowercase with underscores for function and method names to improve readability. get_user_name()
follows this convention.
4. Which of the following is required to package a Python module?
- The Python module should be packaged in a directory with __init__.py in the same directory ✅
- The methods in the Python module should be defined as public methods
- A folder with server.py
- import sys as the first line of code in the Python script
Explanation:
To create a package in Python, you need a directory with an __init__.py
file. This tells Python that the directory should be treated as a package.
5. Which of the following is TRUE about web apps and APIs? (Select two)
- All web apps are APIs, but not all APIs are web apps. ✅
- All APIs allow users to access apps without installing them on their local systems.
- Web apps is a generic term that includes “online” or web-based and “offline” apps.
- Both web apps and APIs link two system parts.
Explanation:
- Though this is a bit of a stretch technically, in the context of this course, they are likely teaching that web apps expose APIs and can function as APIs in many cases.
- Both APIs and web apps serve as bridges connecting different systems—e.g., client-server communication.
Module 1 Graded Quiz: Python Coding Practices and Packaging Concepts
Graded Assignment
6. Which of the following statements are true about web apps? (Select two)
- Web apps help link offline apps.
- Web apps are accessed via a browser over the internet. ✅
- Web apps is a more generic term given to all forms of apps that create a link between any two parts of a system.
- Web apps support CRUD actions. ✅
Explanation:
- Web apps run in browsers and require internet access.
- CRUD stands for Create, Read, Update, Delete—common operations web apps support.
7. In which testing phase do you verify that the application functions within the larger framework?
- Integration testing ✅
- Performance testing
- Unit testing
- User testing
Explanation:
Integration testing checks if different modules or components of an application work together within the overall system.
8. Which of the following statements is TRUE about PyLint?
- PyLint is a Python code compiler.
- PyLint is a Python static code analysis tool. ✅
- PyLint is a Python IDE.
- PyLint is a Python-based package creation tool.
Explanation:
PyLint checks Python code for errors, enforces coding standards, and looks for code smells—all without executing the program.
9. Which of the following is the right way to name constants based on the PEP8 guidelines?
- Date_Of_Birth
- dateOfBirth
- DATE_OF_BIRTH ✅
- date_of_birth
Explanation:
Constants should be written in all uppercase letters with underscores separating words, as per PEP8.
10. When gathering requirements for an app to manage events, the customer mentions that the project’s objective is to improve customer retention.
Which of the following requirements describes the above scenario?
- Technical requirements
- Constraints
- Business requirements ✅
- User requirements
Explanation:
Business requirements define what the business aims to achieve—like improving customer retention, increasing revenue, or reducing churn.
11. Why is it a good practice to build a unit testing class?
- To import the unittest library
- To add one or more assertion methods
- To organize and run multiple unit tests from a single class object ✅
- To test the behavior of functions under all possible conditions.
Explanation:
Unit testing classes help organize related test cases and allow for structured testing using test runners like unittest
.
12. For this question, review the partial module code and the unit test code:

When the unit test is executed, the test fails. Which of the following code statements will you modify for the unit test to pass?
- def test_subract(self)
- self. assertEqual (add (6, 4), 10)
- self. assertEqual (subract (6, 4), 3) ✅
- from math import add
13. Consider the following code in the file my_code.py a directory named mypackage with __init__.py.
def print_hello():
print("Hello")
Which of the following two statements are the right ways to access the function in the method?
- from mypackage import print_hello
print_hello () - from mypackage.my_code import print_hello
print_hello () ✅ - import my_code
print_hello () - from mypackage import my_code
my_code.print_hello () ✅
Explanation:
These two options correctly reference the function inside the my_code.py
file within the mypackage
directory.
14. Which of the following is the general structure for testing a package?
- import {package_name}
- run {package_name}. {module_name}. {function_name} (parameters)
- {package_name} (parameters)
- {package_name}. {module_name}. {function_name} (parameters) ✅
Explanation:
This is the correct format to access a function within a module inside a package in Python.
15. Which of the following is the correct folder structure for the package “MyPackage”?
- MyPackage -> module_1.py, module_2.py
- MyPackage -> module_1-> module_1.py MyPackage -> module_2-> module_2.py
- MyPackage -> module_1.py, module_2.py, init.py
- MyPackage -> module_1.py, ✅ module_2.py, __init__.py
Explanation:
A valid Python package must contain an
__init__.py
file. This file tells Python that the directory should be treated as a package.So the correct structure is:
MyPackage/
├── module_1.py
├── module_2.py
└── __init__.py
Related contents:
Module 2: Web App Deployment using Flask
Module 3: Creating AI Application and Deploy using Flask
You might also like:
Course 1: Introduction to Software Engineering
Course 2: Introduction to Artificial Intelligence (AI)
Course 3: Generative AI: Introduction and Applications
Course 4: Generative AI: Prompt Engineering Basics
Course 5: Introduction to HTML, CSS, & JavaScript
Course 6: Python for Data Science, AI & Development
Course 8: Building Generative AI-Powered Applications with Python
Course 9: Generative AI: Elevate your Software Development Career
Course 10: Software Developer Career Guide and Interview Preparation