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

Example:

l = Lottery(numbers=[9])
l.get_answer() # 9
l.play(1) # False
l.play(9) # 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 l.play(l.get_answer()) is True

test play - Run Test

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