473,554 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

indentation error that I can't comphrehend.

58 New Member
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 7695
bvdet
2,851 Recognized Expert Moderator Specialist
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 New Member
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 New Member
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 Recognized Expert Expert
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 Recognized Expert Moderator Specialist
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 Recognized Expert Expert
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 New Member
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
2125
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 better visualization for example: WorldBegin Color Surface "constant"
147
7625
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 better freedom to the user? Is there any plausible reason behind this? Cheers! Sateesh
177
6892
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 programming languages still being designed with C's syntax? These questions drive me insane. Every waking minute...
5
1179
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 code with the indentation gone. Python code is fragile in this regard. One solution that occurs to me is that a "indentation code" could be...
7
5863
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 because indentation was not right. I checked time and again but still no success. I rewrote the code over again in VI and it ran. Can you please explain...
135
7386
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 which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the...
4
1792
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 appreciated that article, and I have personally seen how fast students learn Python basics compared to other languages, but I think that it's way more...
43
1930
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 acceptable. It does make source easier to read. #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if (argc!=3) {
0
1204
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 my editor. The user would then only need to specify when to decrease indentation. Cheers, Almar
0
7573
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7778
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6114
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5412
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3538
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3525
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.