Hackbright Code Challenges

Find the Range: Solution

Find the Range: Solution

Problem

Find the Range

Whiteboard

Easier

Concepts

Lists, Loops

Download

find-range-solution.zip


range.py
def find_range(nums):
    """Given list of numbers, return smallest & largest number as a tuple."""

    # START SOLUTION

    if len(nums) == 0:
        return (None, None)

    smallest = nums[0]
    largest = nums[0]

    for num in nums:
        if num < smallest:
            smallest = num
        elif num > largest:
            largest = num

    return (smallest, largest)