Below is the pasted part of my code that is coming up with the error "SyntaxErro r: Expected Indented Block".
Edit: When it posts the indents do not show up; so each "<indent>" written indicates a "tab".
Code:
def findRain(allData, target):
'''Uses a binary search to locate rainfall amounts in mm
from the supplied list of dictionaries. target is a
date in the 'yearmonth' value format. The function
assumes that the list has been sorted by increasing
date. The function will raise a ValueError exception if
the year and month in target do not exist in allData.'''
# You must use a binary seach and cannot use any built-
in searches.
low = 0
high = len(allData) - 1
while low <= high:
<indent> mid = (low + high) // 2
print (allData[mid]["yearmonth"])
print (target)
if target < allData[mid]["yearmonth"]:
<indent><indent>high = mid - 1
<indent> elif target > allData[mid]["yearmonth"]:
<indent><indent> low = mid + 1
<indent> else:
<indent><indent> return (allData[mid]["rain"])
<indent>raise ValueError("Target not found")
Comment