Skip to content
dreamcode
dreamcode
Map
Cloud Tracker Class
Section challenge · IntermediatePython
Reward: +50 XP
PROBLEM

Cloud Tracker Class

Write a class CloudTracker with an initializer __init__(self, name, height) (height in meters). Implement a method grow(self, amount) that adds amount to the height. If amount is less than or equal to 0, raise a ValueError. Implement a method get_status(self) that returns '{name} is at {height}m'.

Also write a helper function test_tracker(name, height, grow_amount) that instantiates the class, calls grow(grow_amount), and returns get_status(). If a ValueError is raised, it should catch it and return 'invalid growth'.

Examples
test_tracker('Cumulus', 1000, 500)
'Cumulus is at 1500m'
test_tracker('Nimbus', 2000, -100)
'invalid growth'
solution.py
PYTHON
Saved as you type

Tests

0 of 3 passing
  • normal growth: Cumulus 1000m + 500m → 1500m
    test_tracker('Cumulus', 1000, 500)
    expected 'Cumulus is at 1500m'
  • negative growth → error
    test_tracker('Nimbus', 2000, -100)
    expected 'invalid growth'
  • zero growth → error
    test_tracker('Stratus', 500, 0)
    expected 'invalid growth'
On the line
+50 XP
Pass all 3 tests to claim it.