[PyAR2] .upper()

Coltrey Mather pyar2 at cowsgomoo.org
Sat Aug 6 14:46:00 CEST 2011


You want to use raw_input(), not input().  input() will send whatever
you input to the python interpreter for evaluation and return its
result.  raw_input will return a string of your input.


raw_input(...)
    raw_input([prompt]) -> string

    Read a string from standard input.  The trailing newline is stripped.
    If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
    On Unix, GNU readline is used if enabled.  The prompt string, if given,
    is printed without a trailing newline before reading.


input(...)
    input([prompt]) -> value

    Equivalent to eval(raw_input(prompt)).


On Sat, Aug 6, 2011 at 07:40, Daniel Veazey <daniel at danielveazey.com> wrote:
> Almost a total noob here, getting stumped. Using Python 2.7.1+. Here is my
> code:
>
> while True:
>     reply = input("Enter text: ")
>     if reply == 'stop': break
>     print(reply.upper())
>
> It's supposed to just take the text that the user has entered and print it
> in uppercase, unless the user types 'stop.'
>
> But I get errors when I run it:
>
> Enter text: word
> Traceback (most recent call last):
>   File "upper.py", line 2, in <module>
>     reply = input("Enter text: ")
>   File "<string>", line 1, in <module>
> NameError: name 'word' is not defined
>
> Enter text: stop
> Traceback (most recent call last):
>   File "upper.py", line 2, in <module>
>     reply = input("Enter text: ")
>   File "<string>", line 1, in <module>
> NameError: name 'stop' is not defined
>
> Enter text: two words
> Traceback (most recent call last):
>   File "upper.py", line 2, in <module>
>     reply = input("Enter text: ")
>   File "<string>", line 1
>     two words
>             ^
> SyntaxError: unexpected EOF while parsing
>
> Any tips?
>
>
> _______________________________________________
> PyAR2 mailing list
> PyAR2 at python.org
> http://mail.python.org/mailman/listinfo/pyar2
>
>


More information about the PyAR2 mailing list