Modules in Python

Step-by-step Python programming tutorial

Explore Python's unique solutions to common programming problems, like determining whether a user-inputted number is even or odd. This is a key skill that could benefit you in a variety of programming, data science, or web development careers.

Key Insights

  • The instructor demonstrates how to use Python to solve a popular problem: determining if a user-inputted number is even or odd.
  • The instructor first prompts the user for a number using Python's built-in "input" function.
  • Because inputted information is stored as a string, it must be converted to a numeric data type to perform mathematical operations.
  • The "int" function is used to convert the string into an integer, allowing for mathematical computations.
  • An if-else statement, accompanied by the modulo operator, is used to determine if the user-inputted number is even or odd.
  • The tutorial represents the type of Python training provided at Noble Desktop, enhancing programming, data science, and web development skills.

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.

Play video

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.

Python for Data Science Bootcamp: Live & Hands-on, In NYC or Online, Learn From Experts, Free Retake, Small Class Sizes,  1-on-1 Bonus Training. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

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.

Topics

Learn more in these courses

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram