indentation error that I can't comphrehend.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shing
    New Member
    • Mar 2007
    • 58

    #1

    indentation error that I can't comphrehend.

    Code:
    ################################################################################
    # Module:   XRobo
    # Author:   Shing	
    # Date:     15/03/07
    # Version:  Draft 1.0
    ################################################################################
    # Possible Updates:
    #
    # 
    ################################################################################
    '''
    This module is a hot-headed talk back Robot called XRobo.
    '''
    ################################################################################
    # Log:
    # 18/03/07   Shing - File created
    ################################################################################
    
    print "XRobo,"
    print " "
    
    
    
    while True:
        name = input("What's your name?")
    
        print "Hi Mistar name"
    
    while True:
        robo = raw_input("Start a conversation or Run from XRobo?")
        if robo.lower() == 'exit':
                  break
    
        elif robo.lower() == 'run':
                  break
                
        elif robo.lower() == 'shing':
            print "Yep, that's the guy who made this program, genius isn't he?"
                      
        elif robo.lower() == 'start':
            print "Well if you say so. Sheesh give me a break, I hate talking to"
            print "mortals like you. Anyways, what topic?"  
    
        elif robo.lower() == 'conversation':
            print "Well if you say so. Sheesh give me a break, I hate talking to"
            print "mortals like you. Anyways, what topic?"
    
         else:
             print "Mistar"
    Says theres an error with my indentation level just after "else:"

    Anyone wanna tell me what's going on?

    P.S. If there are any other errors in my code, or things i should do to clean this program up, please tell me.
    Last edited by shing; Mar 18 '07, 04:49 AM. Reason: Thought of something
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by shing
    Code:
    ################################################################################
    # Module:   XRobo
    # Author:   Shing	
    # Date:     15/03/07
    # Version:  Draft 1.0
    ################################################################################
    # Possible Updates:
    #
    # 
    ################################################################################
    '''
    This module is a hot-headed talk back Robot called XRobo.
    '''
    ################################################################################
    # Log:
    # 18/03/07   Shing - File created
    ################################################################################
    
    print "XRobo,"
    print " "
    
    
    
    while True:
        name = raw_input("What's your name?")
    
        print "Hi Mistar name"
    
    while True:
        robo = raw_input("Start a conversation or Run from XRobo?")
        if robo.lower() == 'exit':
                  break
    
        elif robo.lower() == 'run':
                  break
                
        elif robo.lower() == 'shing':
            print "Yep, that's the guy who made this program, genius isn't he?"
                      
        elif robo.lower() == 'start':
            print "Well if you say so. Sheesh give me a break, I hate talking to"
            print "mortals like you. Anyways, what topic?"  
    
        elif robo.lower() == 'conversation':
            print "Well if you say so. Sheesh give me a break, I hate talking to"
            print "mortals like you. Anyways, what topic?"
    
         else:
             print "Mistar"
    Says theres an error with my indentation level just after "else:"

    Anyone wanna tell me what's going on?

    P.S. If there are any other errors in my code, or things i should do to clean this program up, please tell me.
    Python has strict indentation rules. You had an extra space before the else. I modified a couple of things:
    Code:
    name = input("What's your name?")
    
    print "Hi Mistar %s" % name
    
    while True:
        robo = raw_input("%s, start a conversation or Run from XRobo?" % name)

    Comment

    • shing
      New Member
      • Mar 2007
      • 58

      #3
      what does the % and all that mean?

      I think i get the general idea, but i'd like some confirmation. Thanks!

      btw: it also says there is invalid syntax with another "else" line of code :

      Code:
      print "XRobo,"
      print " "
      
      while True:
          name = raw_input("What's your name?")
          
          else name.lower() == print "Hi Mistar name" <--------------------right there.
      
      while True:
          robo = raw_input("Start a conversation or Run from XRobo?")
          if robo.lower() == 'exit':
                    break
      Last edited by shing; Mar 18 '07, 07:17 AM. Reason: Thought of something

      Comment

      • shing
        New Member
        • Mar 2007
        • 58

        #4
        Also, what does while True mean? What would while false do?

        and what is the difference between "raw input" and just "input"?

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by shing
          Also, what does while True mean? What would while false do?

          and what is the difference between "raw input" and just "input"?
          True means just what it sounds like:
          Code:
          if True:
              print "true"
          while True:
          means always run.

          while False:
          means never run.

          raw_input() returns strings.

          Comment

          • bvdet
            Recognized Expert Specialist
            • Oct 2006
            • 2851

            #6
            Originally posted by shing
            Also, what does while True mean? What would while false do?

            and what is the difference between "raw input" and just "input"?
            'True' and 'False' are built-in Boolean values (similar to 1 and 0). 'while False:' would do nothing. 'while false:' would:
            Code:
            Traceback (most recent call last):
              File "<interactive input>", line 1, in ?
            NameError: name 'false' is not defined
            >>>
            'input()' is equivalent to 'eval(raw_input ())'.

            Comment

            • bartonc
              Recognized Expert Expert
              • Sep 2006
              • 6478

              #7
              Originally posted by shing
              what does the % and all that mean?

              I think i get the general idea, but i'd like some confirmation. Thanks!
              % is used in this context (different from numerical) as the "string format" character. This is actuall a little advanced. For now, you can stick with
              Code:
              nameStr = "barton"
              print "hello " + nameStr
              btw: it also says there is invalid syntax with another "else" line of code :

              Code:
              print "XRobo,"
              print " "
              
              while True:
                  name = raw_input("What's your name?")
                  
                  else name.lower() == print "Hi Mistar name" <--------------------right there.
              
              while True:
                  robo = raw_input("Start a conversation or Run from XRobo?")
                  if robo.lower() == 'exit':
                            break
              You left out the : after else
              Code:
                  
                  else:
                      name.lower() == print "Hi Mistar name" <--------------------right there.
              I've added the new line plus indentation for better readability.

              Comment

              • shing
                New Member
                • Mar 2007
                • 58

                #8
                Code:
                nameStr = "barton"
                print "hello " + nameStr
                wouldnt that only give "hello" for anybody called barton?

                Code:
                    after else:
                              name.lower() == print "Hi Mistar name"
                i addded this now and it says there's still something wrong with the else...
                Last edited by shing; Mar 18 '07, 08:05 PM. Reason: lol

                Comment

                Working...