Solution 1

import random

class Lottery(object):
    def __init__(self, numbers=None):
        if numbers is None:
            numbers = range(0, 50)
        self.answer = random.choice(numbers)
    def get_answer(self):
        return self.answer

    def play(self, number):
        if self.answer == number:
            return True
        return False

Lottery Time

Create a class called Lottery with that optionally receives a list numbers containing the possible winning numbers. If numbers is not received as an optional argument, set it to be a list ranging from 0-49. When created, your Lottery object should have an attribute answer created that is random number from the numbers list.

It needs to have two methods:
- get_answer that returns the answer variable for that object
- play that receives a number and returns True if the number matches the answer and False otherwise


l = Lottery(numbers=[9])
l.get_answer() # 9 # False # True

Test Cases

test get answer - Run Test

def test_get_answer():
    l = Lottery(numbers=[9])
    assert l.get_answer() is not None
    assert l.get_answer() == 9

test random range - Run Test

def test_random_range():
    l = Lottery()
    assert l.get_answer() is not None
    assert is True

test play - Run Test

def test_play():
    l = Lottery(numbers=[9])
    assert is False
    assert is True
# Import here! # Define your class here