473,383 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Nested if and expected an indent block

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

Aug 13 '06 #1
7 3544

ka****@gmail.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":
Aug 13 '06 #2

alisonken1 wrote:
ka****@gmail.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

Aug 14 '06 #3
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.

Aug 14 '06 #4

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

Aug 14 '06 #5
ka****@gmail.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

Aug 14 '06 #6

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

Aug 14 '06 #7
ka****@gmail.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
Aug 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dave Benjamin | last post by:
I ran into an odd little edge case while experimenting with functions that create classes on the fly (don't ask me why): >>> def f(x): ... class C(object): ... x = x ... print C.x ......
6
by: oooooo0000000 | last post by:
I have an XML file of varying nesting depth... <catalouge> <item id="1"> <name/> <item id="23"> <name/> <item id="55"> <name/> </item>
21
by: Wladimir Borsov | last post by:
Assume I want to publish a longer article on a web page. One of the paragraphs I want to display with an indent. Read: All text lines of this paragraph should be displayed with (let's say 8) blanks...
2
by: darius | last post by:
Hi I want to do paragraphs with nested indent, like so para 1 .... ......... para 2 ....... ..... para 3 ...... .........
12
by: seajays | last post by:
I've got my page working just as I wanted it - but when I came to validate the XHTML, using W3c's validator it failed. Essentially as far as I can see it the problem is this: 1: <div> 2: <a...
1
by: Christopher P. Winter | last post by:
I'm seeing some unexpected behavior with Text-indent, as shown on this page: http://www.chris-winter.com/Digressions/HP_Kayak/My_Kayak.html I set up the following style rules for footnotes: ...
4
by: Martin Eyles | last post by:
Hi, I am trying to get two divs to align at the bottom of another div. As they are nested in this div, I expected them to be positioned at the bottom of it, using the code below, but they are...
8
by: Sean Givan | last post by:
Hi. I'm new to Python, and downloaded a Windows copy a little while ago. I was doing some experiments with nested functions, and ran into something strange. This code: def outer(): val =...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.