#comments

Discussion in 'Python' started by Ken Parkes, Sep 13, 2004.

  1. Ken Parkes

    Ken Parkes Guest

    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.
     
    Ken Parkes, Sep 13, 2004
    #1
    1. Advertising

  2. Ken Parkes

    F. Petitjean Guest

    On 13 Sep 2004 22:27:32 Ken Parkes <> 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 ....
     
    F. Petitjean, Sep 13, 2004
    #2
    1. Advertising

  3. Ken Parkes

    Ken Parkes Guest

    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.
     
    Ken Parkes, Sep 13, 2004
    #3
  4. Ken Parkes

    Paul McNett Guest

    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
     
    Paul McNett, Sep 13, 2004
    #4
  5. Ken Parkes

    Ken Parkes Guest

    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
     
    Ken Parkes, Sep 13, 2004
    #5
  6. Ken Parkes

    Ken Parkes Guest

    On Mon, 13 Sep 2004 21:30:36 +0000, F. Petitjean wrote:

    > On 13 Sep 2004 22:27:32 Ken Parkes <>
    > 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.
     
    Ken Parkes, Sep 13, 2004
    #6
  7. Ken Parkes

    Larry Bates Guest

    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" <> wrote in message
    news:p...
    >
    > 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
    >
    >
     
    Larry Bates, Sep 13, 2004
    #7
  8. Ken Parkes

    Ken Parkes Guest

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

    Ken.
     
    Ken Parkes, Sep 13, 2004
    #8
  9. Ken Parkes

    Dan Perl Guest

    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" <> wrote in message
    news:p...
    > 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.
    >
     
    Dan Perl, Sep 14, 2004
    #9
  10. Ken Parkes

    Dan Bishop Guest

    Ken Parkes <> wrote in message news:<>...
    > 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 ")
     
    Dan Bishop, Sep 14, 2004
    #10
  11. Ken Parkes

    Ken Parkes Guest

    On Mon, 13 Sep 2004 21:51:17 -0700, Dan Bishop wrote:


    >
    > This isn't related to your question, but why are you using two assignment
    > statements when one will do?
    >
    > myInput = raw_input("Type something ")



    All to do with my background-learning by trial and error. I was simply
    trying various ways of assignment. When one gets long in the tooth read
    stuff tends to evaporate. Got to Handling Exceptions in van Rossum's
    tutorial today and saw the first instance of
    print itemA , itemB
    Now I shall not forget and have a mental link with
    while something : somethingElse
    Two pains for the price of one.

    And thanks to Dan Perl; there's a name to conjure with:)

    Ken.
     
    Ken Parkes, Sep 15, 2004
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad Jones

    Help or comments appreciated.

    Brad Jones, May 18, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    1,249
    Brad Jones \(not CodeGuru Guy!\)
    May 19, 2005
  2. Edison
    Replies:
    2
    Views:
    1,657
    Jonathan Bromley
    Jun 30, 2003
  3. Replies:
    0
    Views:
    1,157
  4. Monk
    Replies:
    10
    Views:
    1,502
    Michael Wojcik
    Apr 20, 2005
  5. Replies:
    4
    Views:
    634
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page