By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

SyntaxError: Expected Indented Block

P: 1
Below is the pasted part of my code that is coming up with the error "SyntaxError: Expected Indented Block".

Expand|Select|Wrap|Line Numbers
  1. def findRain(allData, target):
  2.     '''Uses a binary search to locate rainfall amounts in mm 
  3.     from the supplied list of dictionaries.  target is a 
  4.     date in the 'yearmonth' value format.  The function 
  5.     assumes that the list has been sorted by increasing 
  6.     date. The function will raise a ValueError exception if 
  7.     the year and month in target do not exist in allData.'''
  8.     # You must use a binary seach and cannot use any built- 
  9.     in searches.
  10.     low = 0
  11.     high = len(allData) - 1
  12.     while low <= high:
  13.         <indent> mid = (low + high) // 2
  14.         print (allData[mid]["yearmonth"])
  15.         print (target)
  16.         if target < allData[mid]["yearmonth"]:
  17.             <indent><indent>high = mid - 1
  18.         <indent> elif target > allData[mid]["yearmonth"]:
  19.             <indent><indent> low = mid + 1
  20.         <indent> else:           
  21.             <indent><indent> return (allData[mid]["rain"])   
  22.     <indent>raise ValueError("Target not found")
Edit: When it posts the indents do not show up; so each "<indent>" written indicates a "tab".
Jun 15 '18 #1
Share this Question
Share on Google+
1 Reply


husoski
P: 4
You have begun a multi-line string literal for your docstring (starting with ''') but left out the closing '''. At the end of line 9, add that ''', or insert a line afterward consisting of just the ''' and nothing else. (My preference is to indent it 4 spaces to line up with the text above, but that's optional.)

I can't tell if there are other problems, since the code hasn't pasted correctly. Those "<insert>" tokens look like some sort of markup.
Jun 15 '18 #2

Post your reply

Sign in to post your reply or Sign up for a free account.