Newb ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chad Everett

    #1

    Newb ?

    Hello all,

    Have a problem here with a challenge from a book I am reading.
    Any help is much appreciated.

    I am trying to run a program that asks the user for a statement and then
    prints it out backwards.
    this is what I have.
    It does not print anything out. I assume that I have something out of whack
    with my high and low statements.

    Thanks for you help.


    print "\n\nWelcom e to the Backwards Message Display."
    print
    message = raw_input("\nPl ease Enter a Message.")

    high = len(message)
    low = -len(message)
    print
    print message[high:low]
    print
    print raw_input("Plea se Press Enter to Exit")


  • Paul Watson

    #2
    Re: Newb ?

    Chad Everett wrote:[color=blue]
    > Hello all,
    >
    > Have a problem here with a challenge from a book I am reading.
    > Any help is much appreciated.
    >
    > I am trying to run a program that asks the user for a statement and then
    > prints it out backwards.
    > this is what I have.
    > It does not print anything out. I assume that I have something out of whack
    > with my high and low statements.
    >
    > Thanks for you help.
    >
    >
    > print "\n\nWelcom e to the Backwards Message Display."
    > print
    > message = raw_input("\nPl ease Enter a Message.")
    >
    > high = len(message)
    > low = -len(message)
    > print
    > print message[high:low]
    > print
    > print raw_input("Plea se Press Enter to Exit")[/color]

    Are you sure that this is not a class assignment? You can search the
    messages here for the answer.

    Comment

    • Paul Watson

      #3
      Re: Newb ?

      Chad Everett wrote:[color=blue]
      > Hello all,
      >
      > Have a problem here with a challenge from a book I am reading.
      > Any help is much appreciated.
      >
      > I am trying to run a program that asks the user for a statement and then
      > prints it out backwards.
      > this is what I have.
      > It does not print anything out. I assume that I have something out of whack
      > with my high and low statements.
      >
      > Thanks for you help.
      >
      >
      > print "\n\nWelcom e to the Backwards Message Display."
      > print
      > message = raw_input("\nPl ease Enter a Message.")
      >
      > high = len(message)
      > low = -len(message)
      > print
      > print message[high:low]
      > print
      > print raw_input("Plea se Press Enter to Exit")[/color]

      Are you sure that this is not a class assignment? You can search the
      messages here for the answer.

      Comment

      • Chad Everett

        #4
        Re: Newb ?


        "Paul Watson" <pwatson@redlin epy.com> wrote in message
        news:3tvpqaFv0q 48U1@individual .net...[color=blue]
        > Chad Everett wrote:[color=green]
        >> Hello all,
        >>
        >> Have a problem here with a challenge from a book I am reading.
        >> Any help is much appreciated.
        >>
        >> I am trying to run a program that asks the user for a statement and then
        >> prints it out backwards.
        >> this is what I have.
        >> It does not print anything out. I assume that I have something out of
        >> whack with my high and low statements.
        >>
        >> Thanks for you help.
        >>
        >>
        >> print "\n\nWelcom e to the Backwards Message Display."
        >> print
        >> message = raw_input("\nPl ease Enter a Message.")
        >>
        >> high = len(message)
        >> low = -len(message)
        >> print
        >> print message[high:low]
        >> print
        >> print raw_input("Plea se Press Enter to Exit")[/color]
        >
        > Are you sure that this is not a class assignment? You can search the
        > messages here for the answer.[/color]

        No, I have been out of school way too long. I am 34 trying to learn a new
        trade. I searched the group for the term backwards but I did not get any
        results.


        Comment

        • Chad Everett

          #5
          Re: Newb ?


          "Paul Watson" <pwatson@redlin epy.com> wrote in message
          news:3tvpqaFv0q 48U1@individual .net...[color=blue]
          > Chad Everett wrote:[color=green]
          >> Hello all,
          >>
          >> Have a problem here with a challenge from a book I am reading.
          >> Any help is much appreciated.
          >>
          >> I am trying to run a program that asks the user for a statement and then
          >> prints it out backwards.
          >> this is what I have.
          >> It does not print anything out. I assume that I have something out of
          >> whack with my high and low statements.
          >>
          >> Thanks for you help.
          >>
          >>
          >> print "\n\nWelcom e to the Backwards Message Display."
          >> print
          >> message = raw_input("\nPl ease Enter a Message.")
          >>
          >> high = len(message)
          >> low = -len(message)
          >> print
          >> print message[high:low]
          >> print
          >> print raw_input("Plea se Press Enter to Exit")[/color]
          >
          > Are you sure that this is not a class assignment? You can search the
          > messages here for the answer.[/color]

          No, I have been out of school way too long. I am 34 trying to learn a new
          trade. I searched the group for the term backwards but I did not get any
          results.


          Comment

          • Ben Finney

            #6
            Re: Newb ?

            Chad Everett <everettcc@hotm ail.com> wrote:[color=blue]
            > I searched the group for the term backwards but I did not get any
            > results.[/color]

            You might have better results searching for 'reverse'.

            --
            \ "For certain people, after fifty, litigation takes the place of |
            `\ sex." -- Gore Vidal |
            _o__) |
            Ben Finney

            Comment

            • Ben Finney

              #7
              Re: Newb ?

              Chad Everett <everettcc@hotm ail.com> wrote:[color=blue]
              > I searched the group for the term backwards but I did not get any
              > results.[/color]

              You might have better results searching for 'reverse'.

              --
              \ "For certain people, after fifty, litigation takes the place of |
              `\ sex." -- Gore Vidal |
              _o__) |
              Ben Finney

              Comment

              • Scott David Daniels

                #8
                Re: Newb ?

                Chad Everett wrote:[color=blue]
                > "Paul Watson" <pwatson@redlin epy.com> wrote in message
                > news:3tvpqaFv0q 48U1@individual .net...
                >[color=green]
                >>Chad Everett wrote:[color=darkred]
                >>>high = len(message)
                >>>low = -len(message)
                >>>print
                >>>print message[high:low]
                >>>print
                >>>print raw_input("Plea se Press Enter to Exit")[/color]
                >>
                >>Are you sure that this is not a class assignment? You can search the
                >>messages here for the answer.[/color]
                >
                >
                > No, I have been out of school way too long. I am 34 trying to learn a new
                > trade. I searched the group for the term backwards but I did not get any
                > results.[/color]

                The problem is that negative numbers mean "count from the rightmost end
                of the string or list." Also, you are going high to low without any
                indication that you mean to go backwards.
                [color=blue][color=green][color=darkred]
                >>> message = raw_input("Ente r a Message:")
                >>> print message[: : -1][/color][/color][/color]

                -Scott David Daniels
                scott.daniels@a cm.org

                Comment

                • Scott David Daniels

                  #9
                  Re: Newb ?

                  Chad Everett wrote:[color=blue]
                  > "Paul Watson" <pwatson@redlin epy.com> wrote in message
                  > news:3tvpqaFv0q 48U1@individual .net...
                  >[color=green]
                  >>Chad Everett wrote:[color=darkred]
                  >>>high = len(message)
                  >>>low = -len(message)
                  >>>print
                  >>>print message[high:low]
                  >>>print
                  >>>print raw_input("Plea se Press Enter to Exit")[/color]
                  >>
                  >>Are you sure that this is not a class assignment? You can search the
                  >>messages here for the answer.[/color]
                  >
                  >
                  > No, I have been out of school way too long. I am 34 trying to learn a new
                  > trade. I searched the group for the term backwards but I did not get any
                  > results.[/color]

                  The problem is that negative numbers mean "count from the rightmost end
                  of the string or list." Also, you are going high to low without any
                  indication that you mean to go backwards.
                  [color=blue][color=green][color=darkred]
                  >>> message = raw_input("Ente r a Message:")
                  >>> print message[: : -1][/color][/color][/color]

                  -Scott David Daniels
                  scott.daniels@a cm.org

                  Comment

                  • Mike Meyer

                    #10
                    Re: Newb ?

                    "Chad Everett" <everettcc@hotm ail.com> writes:[color=blue]
                    > print "\n\nWelcom e to the Backwards Message Display."
                    > print
                    > message = raw_input("\nPl ease Enter a Message.")[/color]

                    Since you said it wasn't a school assignment, and I'm a trusting soul,
                    the next line could be:

                    print message[::-1]

                    <mike

                    --
                    Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
                    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

                    Comment

                    • Mike Meyer

                      #11
                      Re: Newb ?

                      "Chad Everett" <everettcc@hotm ail.com> writes:[color=blue]
                      > print "\n\nWelcom e to the Backwards Message Display."
                      > print
                      > message = raw_input("\nPl ease Enter a Message.")[/color]

                      Since you said it wasn't a school assignment, and I'm a trusting soul,
                      the next line could be:

                      print message[::-1]

                      <mike

                      --
                      Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
                      Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

                      Comment

                      • Chad Everett

                        #12
                        Re: Newb ?

                        Hey guys,

                        Thanks for the hint.
                        I found that info last night but I could never get it to print more than
                        just the last letter.
                        or it would only print partially.
                        I was using just a single colon, the double colon did it.

                        Thanks

                        "Chad Everett" <everettcc@hotm ail.com> wrote in message
                        news:f1yef.2059 7$xK1.18635@big news7.bellsouth .net...[color=blue]
                        > Hello all,
                        >
                        > Have a problem here with a challenge from a book I am reading.
                        > Any help is much appreciated.
                        >
                        > I am trying to run a program that asks the user for a statement and then
                        > prints it out backwards.
                        > this is what I have.
                        > It does not print anything out. I assume that I have something out of
                        > whack with my high and low statements.
                        >
                        > Thanks for you help.
                        >
                        >
                        > print "\n\nWelcom e to the Backwards Message Display."
                        > print
                        > message = raw_input("\nPl ease Enter a Message.")
                        >
                        > high = len(message)
                        > low = -len(message)
                        > print
                        > print message[high:low]
                        > print
                        > print raw_input("Plea se Press Enter to Exit")
                        >[/color]


                        Comment

                        • Chad Everett

                          #13
                          Re: Newb ?

                          Hey guys,

                          Thanks for the hint.
                          I found that info last night but I could never get it to print more than
                          just the last letter.
                          or it would only print partially.
                          I was using just a single colon, the double colon did it.

                          Thanks

                          "Chad Everett" <everettcc@hotm ail.com> wrote in message
                          news:f1yef.2059 7$xK1.18635@big news7.bellsouth .net...[color=blue]
                          > Hello all,
                          >
                          > Have a problem here with a challenge from a book I am reading.
                          > Any help is much appreciated.
                          >
                          > I am trying to run a program that asks the user for a statement and then
                          > prints it out backwards.
                          > this is what I have.
                          > It does not print anything out. I assume that I have something out of
                          > whack with my high and low statements.
                          >
                          > Thanks for you help.
                          >
                          >
                          > print "\n\nWelcom e to the Backwards Message Display."
                          > print
                          > message = raw_input("\nPl ease Enter a Message.")
                          >
                          > high = len(message)
                          > low = -len(message)
                          > print
                          > print message[high:low]
                          > print
                          > print raw_input("Plea se Press Enter to Exit")
                          >[/color]


                          Comment

                          • Paul Watson

                            #14
                            Re: Newb ?

                            Chad Everett wrote:[color=blue]
                            > Hey guys,
                            >
                            > Thanks for the hint.
                            > I found that info last night but I could never get it to print more than
                            > just the last letter.
                            > or it would only print partially.
                            > I was using just a single colon, the double colon did it.[/color]

                            If you were using a single colon, then it would print everything except
                            the last character. Use the Python interactive mode for experimentation .

                            $ python
                            Python 2.4.1 (#1, Jul 19 2005, 14:16:43)
                            [GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2
                            Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
                            >>> s = 'abc'
                            >>> s[/color][/color][/color]
                            'abc'[color=blue][color=green][color=darkred]
                            >>> s[:-1][/color][/color][/color]
                            'ab'[color=blue][color=green][color=darkred]
                            >>> s[-1][/color][/color][/color]
                            'c'

                            Comment

                            • Paul Watson

                              #15
                              Re: Newb ?

                              Chad Everett wrote:[color=blue]
                              > Hey guys,
                              >
                              > Thanks for the hint.
                              > I found that info last night but I could never get it to print more than
                              > just the last letter.
                              > or it would only print partially.
                              > I was using just a single colon, the double colon did it.[/color]

                              If you were using a single colon, then it would print everything except
                              the last character. Use the Python interactive mode for experimentation .

                              $ python
                              Python 2.4.1 (#1, Jul 19 2005, 14:16:43)
                              [GCC 4.0.0 20050519 (Red Hat 4.0.0-8)] on linux2
                              Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
                              >>> s = 'abc'
                              >>> s[/color][/color][/color]
                              'abc'[color=blue][color=green][color=darkred]
                              >>> s[:-1][/color][/color][/color]
                              'ab'[color=blue][color=green][color=darkred]
                              >>> s[-1][/color][/color][/color]
                              'c'

                              Comment

                              Working...