Skip to content

Latest commit

 

History

History

readme.md

➡️ Day 6: Using Modules - Python's Superpowers

On Day 6, we learned how to unlock Python's vast ecosystem of pre-built tools by using modules. Instead of writing everything from scratch, we can import powerful code written by others to add new features to our programs instantly.


⭐ Key Concepts Covered:

  • The import Statement: How to bring a module's functionality into our program.
  • The random Module: For generating random numbers (randint), making random choices from lists (choice), and shuffling sequences (shuffle).
  • The math Module: For accessing mathematical constants (pi) and functions (sqrt).
  • The datetime and time Modules: For getting the current date/time and pausing program execution (sleep).
  • Different Import Styles: Using from...import and import...as for cleaner code.

💡 Highlight Snippet:

import random
import time

# A list of possible responses
responses = ["Yes, definitely.", "My reply is no.", "Ask again later."]

print("Thinking...")
time.sleep(2) # Create a dramatic pause

# Use a function from the 'random' module to pick a response
fortune = random.choice(responses)
print(f"The Magic 8-Ball says: '{fortune}'")