Nested if and expected an indent block

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kagard@gmail.com

    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

  • alisonken1

    #2
    Re: Nested if and expected an indent block


    kagard@gmail.co m 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":

    Comment

    • kagard@gmail.com

      #3
      Re: Nested if and expected an indent block


      alisonken1 wrote:
      kagard@gmail.co m 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

      Comment

      • Dustan

        #4
        Re: Nested if and expected an indent block

        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.

        Comment

        • kagard@gmail.com

          #5
          Re: Nested if and expected an indent block


          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
          """
          ^
          IndentationErro r: 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

          Comment

          • Simon Forman

            #6
            Re: Nested if and expected an indent block

            kagard@gmail.co m 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
            """
            ^
            IndentationErro r: 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

            Comment

            • kagard@gmail.com

              #7
              Re: Nested if and expected an indent block


              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

              Comment

              • Pierre Barbier de Reuille

                #8
                Re: Nested if and expected an indent block

                kagard@gmail.co m 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

                Comment

                Working...