I am slightly new to python still. What the end goal is to use the following code to search the list and print out each grb.name in the list. The thing is I am wanting to use user input and I am running into the problem that if the user enters a date that isn't in the list it needs to automatically correct it by adding one until it reaches the next grb_date and then execute the code. This goes for both the start_date and end_date.
for i, grb in enumerate(results): #prolem with multiple grb's in 1 day
try:
grb_date = (re.sub('[A-Z]','',grb.name))
end_results = [i, grb_date]
data[str(grb_date)] = i # this is the important bit
# print (end_results)
except:
pass
#start_date = (input('What is the start date you want: '))
#end_date = (input('What is the end date you want: '))
while 1:
start_date = input('Please choose a start date: ')
end_date = input('Please choose an end date now: ')
try:
while data[start_date] <= data[end_date]:
print (results[data[start_date]].name)
data[start_date] += 1
except KeyError:
while data[start_date] not in end_results:
data[start_date] += 1
x = data[data[start_date]]
print ('Try using this date instead: %d'), x
This is what I currently have. I keep getting KeyError '111111' (or whatever the start_date was if it was wrong).