-
-
################################################################################
-
# 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.
7 7687 bvdet 2,851
Expert Mod 2GB -
-
################################################################################
-
# 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: - 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)
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 : -
-
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
-
-
-
-
Also, what does while True mean? What would while false do?
and what is the difference between "raw input" and just "input"?
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:
while True:
means always run.
while False:
means never run.
raw_input() returns strings.
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: - Traceback (most recent call last):
-
File "<interactive input>", line 1, in ?
-
NameError: name 'false' is not defined
-
>>>
'input()' is equivalent to 'eval(raw_input())'.
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 - nameStr = "barton"
-
print "hello " + nameStr
btw: it also says there is invalid syntax with another "else" line of 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 -
-
else:
-
name.lower() == print "Hi Mistar name" <--------------------right there.
-
I've added the new line plus indentation for better readability.
-
nameStr = "barton"
-
print "hello " + nameStr
-
wouldnt that only give "hello" for anybody called barton? -
after else:
-
name.lower() == print "Hi Mistar name"
-
i addded this now and it says there's still something wrong with the else...
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
| |