Targeted Imports: `from ... import`
Instead of importing the whole `math` module, you can import *only* the functions you need using `from math import function1, function2`. This avoids typing `math.` later. Rewrite the code to import only `sqrt` and `ceil` from `math` and use them directly.
Module Aliasing: `import ... as ...`
Sometimes module names are long, or you want a shorthand. Use `import random as rd` to import the `random` module with the alias `rd`. Then, use `rd.randint(1, 6)` twice to simulate rolling two dice, add their results, and print the total sum.
Module Mashup: `math` & `random`
Let's combine modules! Import both `math` and `random`. Generate a random angle between 0 and 360 degrees using `random.randint()`. Convert this angle to radians using `math.radians()`. Finally, calculate and print the sine of the angle in radians using `math.sin()`.
Choose the Right Import
Sometimes you only need one specific thing. Use the `from ... import ...` style to import *only* the constant `pi` from the `math` module. Then, print the value of `pi`. This is efficient when you need just one or two items.
Module 26 Advanced Practice Complete!
Excellent work mastering different import styles! You're becoming proficient at using Python's modules effectively.
Feel free to review the theory, watch the video lesson, or proceed to the next module!