Hackbright Code Challenges

Find Lucky Numbers: Solution

Find Lucky Numbers: Solution

Problem

Find Lucky Numbers

Whiteboard

Easier

Concepts

Loops, General

Download

lucky-numbers-solution.zip


def lucky_numbers(n):
    """Return n unique random numbers from 1-10 (inclusive)."""

    # START SOLUTION

    nums = list(range(1, 11))
    lucky_nums = []

    for i in range(n):
        num = random.choice(nums)
        nums.remove(num)
        lucky_nums.append(num)

    return lucky_nums