Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > #comments

Reply
Thread Tools

#comments

 
 
Ken Parkes
Guest
Posts: n/a
 
      09-13-2004
Hi,
New to this game. Have tried the following.

data=raw_input("Type something ") # spaces after "something"
myInput=data
print "You typed " myInput # and again
print "The fourth character is "myInput[3] # and again

When I run it in the shell I get error warnings for the second comment
( actually pointing to the t of myInput ) If I remove the comment I get
one for the third comment. What is wrong please?

Ken.

 
Reply With Quote
 
 
 
 
F. Petitjean
Guest
Posts: n/a
 
      09-13-2004
On 13 Sep 2004 22:27:32 Ken Parkes <(E-Mail Removed)> wrote:
> Hi,
> New to this game. Have tried the following.
>
> data=raw_input("Type something ") # spaces after "something"
> myInput=data
> print "You typed " myInput # and again

print "You typed ", myInput # and again # note the comma
> print "The fourth character is "myInput[3] # and again

print "The fourth character is ", myInput[3] # and again # same
>
> When I run it in the shell I get error warnings for the second comment
> ( actually pointing to the t of myInput ) If I remove the comment I get
> one for the third comment. What is wrong please?

The print statement is :
print item1, item2 ....
 
Reply With Quote
 
 
 
 
Ken Parkes
Guest
Posts: n/a
 
      09-13-2004
On Mon, 13 Sep 2004 22:27:32 +0100, Ken Parkes wrote:


Oops, sorry that should have been


data=raw_input("Type something ") # spaces after "something"
myInput=data
print "You typed " myInput # and again
print "The fourth character is " myInput[3] # and again

Ken.

 
Reply With Quote
 
Paul McNett
Guest
Posts: n/a
 
      09-13-2004
Your subject is about comments, but your problem is with
your print statements. See below.

Ken Parkes writes:

> data=raw_input("Type something ") # spaces after
> "something" myInput=data
> print "You typed " myInput # and again
> print "The fourth character is " myInput[3] # and
> again


Try this:

data=raw_input("Type something ") # spaces after "something"
myInput=data
print "You typed %s" % myInput # and again
try:
print "The fourth character is %s" % myInput[3] # and again
except IndexError:
print "There is no fourth character."

--
Paul McNett
Independent Software Consultant
http://www.paulmcnett.com
 
Reply With Quote
 
Ken Parkes
Guest
Posts: n/a
 
      09-13-2004

Oh lord, start again:-

data=raw_input("Type something ") # spacer after "something"
myInput=data
print "You typed " myInput # and again
print "The fourth character is "myInput[3] # and again


 
Reply With Quote
 
Ken Parkes
Guest
Posts: n/a
 
      09-13-2004
On Mon, 13 Sep 2004 21:30:36 +0000, F. Petitjean wrote:

> On 13 Sep 2004 22:27:32 Ken Parkes <(E-Mail Removed)>
> wrote:
>> Hi,
>> New to this game. Have tried the following.
>>
>> data=raw_input("Type something ") # spaces after "something"
>> myInput=data
>> print "You typed " myInput # and again

> print "You typed ", myInput # and again # note the comma
>> print "The fourth character is "myInput[3] # and again

> print "The fourth character is ", myInput[3] # and again # same
>>
>> When I run it in the shell I get error warnings for the second comment (
>> actually pointing to the t of myInput ) If I remove the comment I get
>> one for the third comment. What is wrong please?

> The print statement is :
> print item1, item2 ....


Ah, I see, thank you for that. A follow up please. Do you see the last
line beginning with < print "The fourth..... > ? Pan is chopping the
lines up on my monitor.

Thanks Ken.
 
Reply With Quote
 
Larry Bates
Guest
Posts: n/a
 
      09-13-2004
Not a comment problem. You need commas after
literals in the print statements

print "You typed", myInput # and again

or

print "You typed %s" % myInput # and again

Larry Bates
Syscon, Inc.


"Ken Parkes" <(E-Mail Removed)> wrote in message
newsan.2004.09.13.21.36.41.766093@NOSPAMrosecott .ukfsn.org...
>
> Oh lord, start again:-
>
> data=raw_input("Type something ") # spacer after "something"
> myInput=data
> print "You typed " myInput # and again
> print "The fourth character is "myInput[3] # and again
>
>



 
Reply With Quote
 
Ken Parkes
Guest
Posts: n/a
 
      09-13-2004


Thanks to all for the wisdom, one small step etc. And Pan sorted, not
bad for an evenings work.

Ken.


 
Reply With Quote
 
Dan Perl
Guest
Posts: n/a
 
      09-14-2004
You're missing a comma between the arguments in "print". Here is how it
should be:
data=raw_input("Type something ") # spaces after "something"
myInput=data
print "You typed ", myInput # and again
print "The fourth character is ", myInput[3] # and again


"Ken Parkes" <(E-Mail Removed)> wrote in message
newsan.2004.09.13.21.27.31.291385@NOSPAMrosecott .ukfsn.org...
> Hi,
> New to this game. Have tried the following.
>
> data=raw_input("Type something ") # spaces after "something"
> myInput=data
> print "You typed " myInput # and again
> print "The fourth character is "myInput[3] # and again
>
> When I run it in the shell I get error warnings for the second comment
> ( actually pointing to the t of myInput ) If I remove the comment I get
> one for the third comment. What is wrong please?
>
> Ken.
>



 
Reply With Quote
 
Dan Bishop
Guest
Posts: n/a
 
      09-14-2004
Ken Parkes <(E-Mail Removed)> wrote in message news:<pan.2004.09.13.21.27.31.291385@NOSPAMrosecot t.ukfsn.org>...
> Hi,
> New to this game. Have tried the following.
>
> data=raw_input("Type something ") # spaces after "something"
> myInput=data


This isn't related to your question, but why are you using two
assignment statements when one will do?

myInput = raw_input("Type something ")
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments