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.