Exercise 1: Introduction to Modules
Welcome to Python 2, Lesson 6! Today, we'll learn about modules in Python. Modules are files containing Python code that can be imported and used in other Python programs.
What are Modules?
Modules are reusable pieces of code that can be imported into your Python programs. They help organize and structure your code, making it easier to maintain and reuse.
Python comes with many built-in modules that you can use right away. Let's start by importing and using the 'math' module:
Now it's your turn! Import the 'random' module and use it to generate random numbers:
- Import the 'random' module
- Generate a random integer between 1 and 10 (inclusive) using random.randint()
- Generate a random float between 0 and 1 using random.random()
- Print both results
# Import the random module and generate random numbers here