Skip to main content
Noble Desktop/2 min read

Modules in Python

Build a Python Script

1

Define the Goal

Single, specific outcome — avoid scope creep in scripts.

2

Outline Functions

Break logic into functions with clear inputs/outputs.

3

Add Error Handling

try/except for expected failures, raise for unexpected.

4

Argparse for CLI

argparse turns a script into a real command-line tool.

Master Python at Noble Desktop

Noble Desktop's Python Programming Immersive covers AI APIs, data analysis, and modern Python development.

In this video, we're going to look at how to use Modules in Python

Video Transcription

Hi, My Name is Art and I Teach Python at Noble Desktop. in This Video, I'm Going to Show You How to Use Modular to Solve a Popular Problem in Python.

The problem is to ask the user for a number and then print if the number is even or odd. First, let's ask the user for the number. We can use the built-in function "input": "Give me a number".

When the user runs the program, they will be prompted to enter a number, let's say 5. The input is stored with the variable, but it is a string. In order to do math with the number, we need to convert it to a numeric data type. We can use the same variable name and the "int" function to convert it to an integer.

Now we can use an if-else statement to check if the number is even or odd. We can use the modulo operator to check for a remainder. If the number is divisible by two and the remainder is zero, then we can print "even number". Otherwise, the number is odd.

Thank you.