Nested if and expected an indent block
7 answers - 1032 bytes -

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, 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 = ""
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
No.1 | | 279 bytes |
| 
kagard (AT) gmail (DOT) com wrote:
Greetings:
<snip>
elif q.lower() == "some" # s in some is highlighted
<snip>
Any ideas? Thanks in advance.
Keith
Would the missing colon have something to do with it?
elif q.lower() == "some":
No.2 | | 618 bytes |
| 
alisonken1 wrote:
kagard (AT) gmail (DOT) com wrote:
Greetings:
<snip>
elif q.lower() == "some" # s in some is highlighted
<snip>
Any ideas? Thanks in advance.
Keith
Would the missing colon have something to do with it?
elif q.lower() == "some":
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
No.3 | | 425 bytes |
| 
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.
No.4 | | 496 bytes |
| 
Dustan wrote:
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
No.5 | | 809 bytes |
| 
kagard (AT) gmail (DOT) com wrote:
Dustan wrote:
--
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
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
No.6 | | 834 bytes |
| 
Simon Forman wrote:
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.
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
No.7 | | 1239 bytes |
| 
kagard (AT) gmail (DOT) com wrote:
Simon Forman wrote:
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.
>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
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