LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Guided Project: Mobile App for Lottery Addiction (5/8)

Screen Link:
https://app.dataquest.io/m/382/guided-project%3A-mobile-app-for-lottery-addiction/6/multi-ticket-probability

CODE:

def check_historical_occurrence(user_numbers, historical_numbers):   
    user_numbers_set = set(user_numbers)
    check_occurrence = historical_numbers == user_numbers_set
    n_occurrences = check_occurrence.sum()
    
    if n_occurrences == 0:
        print('''The combination {} has never occured.
This doesn't mean it's more likely to occur now. Your chances to win the big prize in the next drawing using the combination {} are 0.0000072%.
In other words, you have a 1 in 13,983,816 chances to win.'''.format(user_numbers, user_numbers))
        
    else:
        print('''The number of times combination {} has occured in the past is {}.
Your chances to win the big prize in the next drawing using the combination {} are 0.0000072%.
In other words, you have a 1 in 13,983,816 chances to win.'''.format(user_numbers, n_occurrences,
                                                                            user_numbers))
test_input_3 = [33, 36, 37, 39, 8, 41]
check_historical_occurrence(test_input_3,winning_number_list)

What I expected to happen:
I didn’t understand the solution you guys had for the “check_historical_occurrence()” function.

When I tried using it I got the error message below. The biggest confusion was with “check_occurrence = historical_numbers == user_numbers_set”. I thought it should’ve been “historical_numbers IN user_numbers_set” to see if the value was in the winning_numbers, but then I also got an error message. Where did I go wrong in my code and how do I check if a lottery number is in winning_numbers? Please let me know if you need any additional information.

What actually happened:
ERROR MESSAGE:

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

This is additional code on how I got the winning_numbers list

def lotto_number_list(row):
    row = row.iloc[4:10]
    values = row.values
    return values
winning_number_list  = lotto_data.apply(lotto_number_list,axis=1)
lotto_data["winning_numbers"] = lotto_data.apply(lotto_number_list,axis=1)
lotto_data["winning_numbers"]
lotto_data.columns = lotto_data.columns.str.upper()
winning_number_list.head()