Re: Floating point calculation problem

Discussion in 'Python' started by Chris Rebert, Feb 2, 2013.

  1. Chris Rebert

    Chris Rebert Guest

    On Sat, Feb 2, 2013 at 2:27 AM, Schizoid Man <> wrote:
    > I have a program that performs some calculations that runs perfectly on
    > Python 2.7.3. However, when I try to execute it on Python 3.3.0 I get the
    > following error:
    > numer = math.log(s)
    > TypeError: a float is required
    >
    > The quantity s is input with the following line: s = input("Enter s: ")
    >
    > To get rid of the compile error, I can cast this as a float: s =
    > float(input("Enter s: "))

    <snip>
    > How is
    > Python dynamically typed if I need to cast (in version 3.3.0 at least) to
    > get rid of the compile error?


    It's *not* a compile error; it's a *runtime* error raised inside
    math.log() when that function is called (with an invalid argument).
    IIRC, the only compile-time error in Python is SyntaxError (and its
    subclass, IndentationError).
    Python is also strongly-typed, which is why, at runtime, an exception
    is thrown instead of some implicit type coercion being attempted; such
    coercion tends to hide genuine bugs, hence why Python avoids it.

    Regards,
    Chris
    Chris Rebert, Feb 2, 2013
    #1
    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. bei
    Replies:
    0
    Views:
    222
  2. bei
    Replies:
    4
    Views:
    370
  3. Saraswati lakki
    Replies:
    0
    Views:
    1,275
    Saraswati lakki
    Jan 6, 2012
  4. Hyun chul Park

    Floating point calculation problem

    Hyun chul Park, Jul 8, 2008, in forum: Ruby
    Replies:
    3
    Views:
    95
    Axel Etzold
    Jul 8, 2008
  5. Chris Angelico

    Re: Floating point calculation problem

    Chris Angelico, Feb 2, 2013, in forum: Python
    Replies:
    16
    Views:
    221
    Michael Torrie
    Feb 3, 2013
Loading...

Share This Page