I have been tasked with to write a program that guesses a date the user is thinking of where the AI asks 10, or less, 'yes' or 'no' questions. Essentially this is just a reverse number guessing game. I have written a function that creates a list of all the days of the year, from Jan 1 to Dec 31, basically 365 entries.
def Calendar(monthNames, numDaysInMonth):
'''Return a list of elements, each element
is a date in a calendar year'''
if len(monthNames) != len(numDaysInMonth):
return []
dates = []
idx = 0
while idx < len(monthNames):
for date in range(1, numDaysInMonth[idx] + 1):
dates.append(monthNames[idx] + " " + str(date))
idx = idx + 1
return dates
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
numDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
print(Calendar(months, numDays))
Obviously the print statement is not needed, but was used to check my work. Now, my question is, where do I go from here? Since the computer is asking 'yes' or 'no' questions, I'd like for the program to narrow down by dividing the number in half until the "date" is zeroed in, and then use that number to point to the index from the function I've already created. By no means am I asking for this to be done for me, but a nice nudge in the right direction would be nice. I'm lost on what to do next.