Nested if and expected an indent block

K

kagard

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 the syllogism. Python tells me
that it is expecting an indented block at the s in "some". I can see
what I'm doing wrong. Here's the code:

def class_stmt(q,c):
"""
This function classifies a statement according to the rules of
categorical syllogisms and returns A, E, I, O to identify the
statement type.
"""
if q.lower() == "all":
if "not" in c:
stmt_type = "E"
else:
stmt_type = "A"
elif q.lower() == "some" # s in some is highlighted
if "not" in c:
stmt_type = "O"
else:
stmt_type = "I"
elif q.lower() == "no":
if "not" in c:
stmt_type = "A"
else:
stmt_type = "E"
else:
if "not" in c:
stmt_type = "E"
else:
stmt_type = "A"

return stmt_type

Any ideas? Thanks in advance.

Keith
 
K

kagard

alisonken1 said:
Would the missing colon have something to do with it?

Thanks for the replies:

I'm sorry, the colon is there in the original, I accidentally blew it
off when I added the comment. The only information I get from IDLE is a
dialog box that says:

Syntax Error
There's an error in your program:
expected an indented block

Keith
 
D

Dustan

Thanks for the replies:
I'm sorry, the colon is there in the original, I accidentally blew it
off when I added the comment. The only information I get from IDLE is a
dialog box that says:

Syntax Error
There's an error in your program:
expected an indented block

Keith

To see the full traceback, assuming you're using windows, you need to
run it on the Command prompt.
 
K

kagard

Dustan said:
To see the full traceback, assuming you're using windows, you need to
run it on the Command prompt.

Hi Dustan:

Here's the traceback:

C:\docs\Python>SylloSolver.py
File "C:\docs\Python\SylloSolver.py", line
"""
^
IndentationError: expected an indented block

I got rid of the triple quote string at the start of the function, and
that cleared up the problem, though I don't know why.

Thanks

Keith
 
S

Simon Forman

Hi Dustan:

Here's the traceback:

C:\docs\Python>SylloSolver.py
File "C:\docs\Python\SylloSolver.py", line
"""
^
IndentationError: expected an indented block

I got rid of the triple quote string at the start of the function, and
that cleared up the problem, though I don't know why.

Thanks

Keith

Ah, yes. The docstring for a function (or at least its first
triple-quote) must be indented to the same degree as its statements.
(If you're using IDLE it should have indented it for you when you hit
return after the def statement.)

HTH,
~Simon
 
K

kagard

Simon said:
Ah, yes. The docstring for a function (or at least its first
triple-quote) must be indented to the same degree as its statements.
(If you're using IDLE it should have indented it for you when you hit
return after the def statement.)

HTH,
~Simon

Hi Simon:

Thanks. I code in VB / VBA, and use indented structure, but it's not
enforced they way it is in Python - still getting used to that. Also, I
got goofed up editing some of the code in VIM, indenting with tabs, and
then switching to IDLE, with space indentation. Whoops...

Thanks for all the help everyone, my first Python program is now
working!

Keith
 
P

Pierre Barbier de Reuille

Hi Simon:

Thanks. I code in VB / VBA, and use indented structure, but it's not
enforced they way it is in Python - still getting used to that. Also, I
got goofed up editing some of the code in VIM, indenting with tabs, and
then switching to IDLE, with space indentation. Whoops...

Thanks for all the help everyone, my first Python program is now
working!

Keith

Tips: if you're coding with VIM, put "set expandtab" in your config
file. That way, each tab will be expanded into the corresponding number
of spaces ... Whatever the language, I find it always a bad idea to mix
spaces and tabs, and I prefer spaces ...

Pierre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top