473,320 Members | 2,133 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,320 software developers and data experts.

indentation error that I can't comphrehend.

58
Expand|Select|Wrap|Line Numbers
  1.  
  2. ################################################################################
  3. # Module:   XRobo
  4. # Author:   Shing    
  5. # Date:     15/03/07
  6. # Version:  Draft 1.0
  7. ################################################################################
  8. # Possible Updates:
  9. #
  10. ################################################################################
  11. '''
  12. This module is a hot-headed talk back Robot called XRobo.
  13. '''
  14. ################################################################################
  15. # Log:
  16. # 18/03/07   Shing - File created
  17. ################################################################################
  18.  
  19. print "XRobo,"
  20. print " "
  21.  
  22.  
  23.  
  24. while True:
  25.     name = input("What's your name?")
  26.  
  27.     print "Hi Mistar name"
  28.  
  29. while True:
  30.     robo = raw_input("Start a conversation or Run from XRobo?")
  31.     if robo.lower() == 'exit':
  32.               break
  33.  
  34.     elif robo.lower() == 'run':
  35.               break
  36.  
  37.     elif robo.lower() == 'shing':
  38.         print "Yep, that's the guy who made this program, genius isn't he?"
  39.  
  40.     elif robo.lower() == 'start':
  41.         print "Well if you say so. Sheesh give me a break, I hate talking to"
  42.         print "mortals like you. Anyways, what topic?"  
  43.  
  44.     elif robo.lower() == 'conversation':
  45.         print "Well if you say so. Sheesh give me a break, I hate talking to"
  46.         print "mortals like you. Anyways, what topic?"
  47.  
  48.      else:
  49.          print "Mistar"
  50.  
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.
Mar 18 '07 #1
7 7687
bvdet
2,851 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1.  
  2. ################################################################################
  3. # Module:   XRobo
  4. # Author:   Shing    
  5. # Date:     15/03/07
  6. # Version:  Draft 1.0
  7. ################################################################################
  8. # Possible Updates:
  9. #
  10. ################################################################################
  11. '''
  12. This module is a hot-headed talk back Robot called XRobo.
  13. '''
  14. ################################################################################
  15. # Log:
  16. # 18/03/07   Shing - File created
  17. ################################################################################
  18.  
  19. print "XRobo,"
  20. print " "
  21.  
  22.  
  23.  
  24. while True:
  25.     name = raw_input("What's your name?")
  26.  
  27.     print "Hi Mistar name"
  28.  
  29. while True:
  30.     robo = raw_input("Start a conversation or Run from XRobo?")
  31.     if robo.lower() == 'exit':
  32.               break
  33.  
  34.     elif robo.lower() == 'run':
  35.               break
  36.  
  37.     elif robo.lower() == 'shing':
  38.         print "Yep, that's the guy who made this program, genius isn't he?"
  39.  
  40.     elif robo.lower() == 'start':
  41.         print "Well if you say so. Sheesh give me a break, I hate talking to"
  42.         print "mortals like you. Anyways, what topic?"  
  43.  
  44.     elif robo.lower() == 'conversation':
  45.         print "Well if you say so. Sheesh give me a break, I hate talking to"
  46.         print "mortals like you. Anyways, what topic?"
  47.  
  48.      else:
  49.          print "Mistar"
  50.  
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:
Expand|Select|Wrap|Line Numbers
  1. name = input("What's your name?")
  2.  
  3. print "Hi Mistar %s" % name
  4.  
  5. while True:
  6.     robo = raw_input("%s, start a conversation or Run from XRobo?" % name)
Mar 18 '07 #2
shing
58
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 :

Expand|Select|Wrap|Line Numbers
  1.  
  2. print "XRobo,"
  3. print " "
  4.  
  5. while True:
  6.     name = raw_input("What's your name?")
  7.  
  8.     else name.lower() == print "Hi Mistar name" <--------------------right there.
  9.  
  10. while True:
  11.     robo = raw_input("Start a conversation or Run from XRobo?")
  12.     if robo.lower() == 'exit':
  13.               break
  14.  
  15.  
  16.  
  17.  
Mar 18 '07 #3
shing
58
Also, what does while True mean? What would while false do?

and what is the difference between "raw input" and just "input"?
Mar 18 '07 #4
bartonc
6,596 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. if True:
  2.     print "true"
while True:
means always run.

while False:
means never run.

raw_input() returns strings.
Mar 18 '07 #5
bvdet
2,851 Expert Mod 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "<interactive input>", line 1, in ?
  3. NameError: name 'false' is not defined
  4. >>> 
'input()' is equivalent to 'eval(raw_input())'.
Mar 18 '07 #6
bartonc
6,596 Expert 4TB
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
Expand|Select|Wrap|Line Numbers
  1. nameStr = "barton"
  2. print "hello " + nameStr
btw: it also says there is invalid syntax with another "else" line of code :

Expand|Select|Wrap|Line Numbers
  1.  
  2. print "XRobo,"
  3. print " "
  4.  
  5. while True:
  6.     name = raw_input("What's your name?")
  7.  
  8.     else name.lower() == print "Hi Mistar name" <--------------------right there.
  9.  
  10. while True:
  11.     robo = raw_input("Start a conversation or Run from XRobo?")
  12.     if robo.lower() == 'exit':
  13.               break
  14.  
  15.  
  16.  
  17.  
You left out the : after else
Expand|Select|Wrap|Line Numbers
  1.  
  2.     else:
  3.         name.lower() == print "Hi Mistar name" <--------------------right there.
  4.  
I've added the new line plus indentation for better readability.
Mar 18 '07 #7
shing
58
Expand|Select|Wrap|Line Numbers
  1. nameStr = "barton"
  2. print "hello " + nameStr
  3.  
wouldnt that only give "hello" for anybody called barton?

Expand|Select|Wrap|Line Numbers
  1.     after else:
  2.               name.lower() == print "Hi Mistar name"
  3.  
i addded this now and it says there's still something wrong with the else...
Mar 18 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Hilbert | last post by:
Hello, I'm using python to output RIB streams for Renderman. The RIB stream is a bunch of statements which describes a 3d image. The Rib standard allows for blocks which we usually indent for...
147
by: Sateesh | last post by:
Hi, I am a beginner in Python, and am wondering what is it about the indentation in Python, without which python scripts do not work properly. Why can't the indentation not so strict so as to give...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
5
by: smichr | last post by:
I have (inadvertently) wiped out the functionality of my personal python snippets by eliminating leading space. I have also just visited http://www.python.org/tim_one/000419.html and saw a piece of...
7
by: diffuser78 | last post by:
I am a newbie to Python. I am mainly using Eric as the IDE for coding. Also, using VIM and gedit sometimes. I had this wierd problem of indentation. My code was 100% right but it wont run...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
4
by: bearophileHUGS | last post by:
This is the best praise of semantic indentation I have read so far, by Chris Okasaki: http://okasaki.blogspot.com/2008/02/in-praise-of-mandatory-indentation-for.html A quotation: I have...
43
by: Bill Cunningham | last post by:
I have had several complaints by some people who wish to help me and I wish to get the problem straight. I wrote this small utility myself and added some indentation and I wonder if it is...
0
by: Almar Klein | last post by:
Hi Eric, First of all, I like your initiative. I'm not sure if I undestand you correctly, but can't you just increase indentation after each line that ends with a colon? That's how I do it in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.