0
0
Pythonprogramming~15 mins

Importing specific items in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Importing Specific Items in Python
📖 Scenario: You are working on a small program that needs to use only certain functions from Python's built-in math module. Instead of importing the whole module, you want to import just the specific functions you need.
🎯 Goal: Learn how to import specific items from a module and use them in your program.
📋 What You'll Learn
Create a list of numbers
Import specific functions sqrt and pow from the math module
Use the imported functions to calculate square roots and powers
Print the results
💡 Why This Matters
🌍 Real World
Importing only the needed functions from a module helps keep programs efficient and clear, especially when working on larger projects.
💼 Career
Many programming jobs require you to use libraries and modules efficiently. Knowing how to import specific items is a basic but important skill.
Progress0 / 4 steps
1
Create a list of numbers
Create a list called numbers with these exact values: 4, 9, 16, 25.
Python
Need a hint?

Use square brackets [] to create a list and separate numbers with commas.

2
Import specific functions from math module
Write an import statement to import only the sqrt and pow functions from the math module.
Python
Need a hint?

Use the syntax from module_name import item1, item2.

3
Calculate square roots and powers
Create two lists: roots containing the square roots of each number in numbers using sqrt, and powers containing each number raised to the power of 2 using pow. Use a for loop with variable num to iterate over numbers.
Python
Need a hint?

Use append() to add items to a list inside the loop.

4
Print the results
Print the roots list and then print the powers list.
Python
Need a hint?

Use two print() statements, one for each list.