-
-
################################################################################
-
# 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 7695 bvdet 2,851
Recognized Expert Moderator Specialist -
-
################################################################################
-
# 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"?
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:
while True:
means always run.
while False:
means never run.
raw_input() returns strings.
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: - Traceback (most recent call last):
-
File "<interactive input>", line 1, in ?
-
NameError: name 'false' is not defined
-
>>>
'input()' is equivalent to 'eval(raw_input ())'.
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 - 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 better visualization for example:
WorldBegin
Color
Surface "constant"
|
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
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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) {
|
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
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |