7. Python Modules, Packages & Project Organization

Modules & Package Structure

# Reusable helper module: utils/string_helper.py
def clean_currency(raw_price: str) -> float:
    return float(raw_price.replace("$", "").strip())

# Importing in page or test files:
from utils.string_helper import clean_currency
import datetime as dt

price = clean_currency(" $49.99 ")

Task

  • Implement safe_convert_price(raw_price: str) -> float:
  • 1. Strip leading/trailing whitespace.
  • 2. Remove any "$" character.
  • 3. Convert and return as float. Return 0.0 if empty or invalid.
πŸ’‘Common doubts
Did you like the problem?
Lesson 7 of 43
Python
Loading code editor…
Next