math.sqrt() in new 3.0 version : solution in input()

John Machin sjmachin at lexicon.net
Fri Dec 26 22:22:09 EST 2008


On Dec 27, 1:34 pm, David Lemper wrote:
>
> Problem is the new input() function. Yields a string.
>
> Thanks to Scott, Chris, Gabriel & John.
>
> Some thought I was not using the Python 3 command line.
> I was :  Python 3.0 (r30:67507...
> Erratic behavior was that I was sometimes using n = input()
> and sometimes entering the integer directly into the
> math.sqrt() function, eg s = math.sqrt(4194304)
>
> I cannot find a mention of this in "The Python Tutorial
> release 3.1"   The I&O section discusses output formatting
> and reading & writing text files.

Yes, it's not in the Tutorial. But you must have found out about its
existence somewhere ... 2.x manuals?

> John pointed out its in Guido's "What's New in Python3.0"
> Indeed its mentioned in PEP 3111, near end of What's New
> and somewhat obscurely. " raw_input() was renamed to input().
> That is the new input() function function reads a line from
> sys.stdin . . ."                          

If you are sticking to 3.0, then you're not in the target audience for
"What's New in Python3.0". Just read the docs on the input function:
   http://docs.python.org/3.0/library/functions.html#input
or use help() at the interactive prompt:

Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help(input)
Help on built-in function input in module builtins:

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

    Read a string from standard input.  The trailing newline is
stripped.
[snip]

HTH,
John



More information about the Python-list mailing list