473,513 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SyntaxError: Expected Indented Block

1 New Member
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
2 3752
husoski
4 New Member
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
evanbung
1 New Member
Putting in an extra space or leaving one out where it is needed will surely generate an error message . Some common causes of this error include:
  • Forgetting to indent the statements within a compound statement
  • Forgetting to indent the statements of a user-defined function.

The error message IndentationError: expected an indented block would seem to indicate that you have an indentation error. It is probably caused by a mix of tabs and spaces. The indentation can be any consistent white space . It is recommended to use 4 spaces for indentation in Python, tabulation or a different number of spaces may work, but it is also known to cause trouble at times. Tabs are a bad idea because they may create different amount if spacing in different editors .
Mar 2 '20 #3

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

Similar topics

39
13370
by: eruanion | last post by:
Hi, I've been working on this for a while now and I can't seem to find out what is wrong with my code. I have 2 files one c3common.js which only contains javascript functions for my main html page...
7
3547
by: kagard | last post by:
Greetings: I'm brand new to Python and decided to write a syllogism solver for a class I'm taking. At the start of the program, I define a function that classifies the type of each statement in...
3
2421
by: Paddy3118 | last post by:
Not python: but python type indented text Notice the blank line above. It could have several spaces or tabs, and still be a part of the block beginning 'Not python:': The block ends at the
6
2923
by: Harlan Messinger | last post by:
Please take a look at http://www.gavelcade.com/list_next_to_float.html How can I style a list so that if it appears next to a left-floated box as the first list does in this example, the list...
3
4469
by: cwggenius | last post by:
Getting the following error. But I cannot figure out why. Could someone please alter my code and explain where I am going wrong? ./checkprocess2.py File "./checkprocess2.py", line 19 ...
2
11906
by: Bryan Vargas | last post by:
I keep getting the same "expected indented block" when ever I run my code. from myro import* init("simulator") def main(): for x in range(10): #repeats code in loop 10 times
1
4309
by: leiel huang | last post by:
There 's a indentation error but i don't know what's wrong with it. the error says File "./class_question.py", line 12 self.dic = #array of hash tables for input data...
1
1939
by: mirshany | last post by:
I could understand yet what indent mean, how to write a block of code in example. IndentationError: expected an indented block >>> for letter in 'Python': # First Example ... if letter ==...
3
2145
by: Aviador22 | last post by:
Resulta que cuando pongo este código: >>> edad = 12 >>> if edad == 12: ... print ('Hola') File "(stdin)", line 2 print('Hola') IdentationError: expected an indented block Help :(
1
1475
by: gearedhead | last post by:
name = input('What is your name?\n') print('Hi, %s.' % name) work = input('What do u do For Living?\n') print('Oh thats Great') hobby = input("What is ur Hobby?\n") if hobby == 'work': print...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7537
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.