Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38067

Re: Floating point calculation problem

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'error:': 0.05; 'float': 0.05; '*not*': 0.07; 'compile-time': 0.07; 'dynamically': 0.07; 'line:': 0.07; 'performs': 0.07; 'raised': 0.07; 'python': 0.09; 'least)': 0.09; 'tends': 0.09; 'thrown': 0.09; 'typed': 0.09; 'typeerror:': 0.09; 'cc:addr :python-list': 0.10; 'sat,': 0.15; 'bugs,': 0.16; 'coercion': 0.16; 'why,': 0.16; 'wrote:': 0.17; '(in': 0.18; 'input': 0.18; 'feb': 0.19; 'implicit': 0.22; 'subject:problem': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chris': 0.28; 'function': 0.30; 'error': 0.30; '(and': 0.32; 'rid': 0.33; '(with': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'execute': 0.37; 'being': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'called': 0.39; 'genuine': 0.62; 'cast': 0.65; '2013': 0.84; 'calculations': 0.84; 'sender:addr:chris': 0.84; 'to:none': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type; bh=09xfXoQaSyy+ArtFenh+Hk2oPUt5LeluUUwkWauKNFg=; b=LSdinGUgPxo9aREJeDiFWFyzpShefqVGTgHoyuuTwWLprVhEHuuFtLs5xZdIneZd/x X+Hto2YLy1EyXbiYtMcmyKx4HCDOtmAOTwv+owQR9yWufRwOWeVD+IusfkKp5LJB//Oe NlXYEO43u3rya6k6urwDZOs/in2nv1+zpEI9I=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :x-gm-message-state; bh=09xfXoQaSyy+ArtFenh+Hk2oPUt5LeluUUwkWauKNFg=; b=TpRMlQ1+HxI+7Uonb0D+adPCdjdyhPqi+52anq4UhOxfkPs985F1TdQZwLwKX+3MuT Q53z0XMo5lAIAMnjjcab65mfI8ehSA2jAu/g/KeVDUQQHO/OR3Y4T9zcYbWRaEA3/aQR /mhPbYG3mFGUFpJ0wT1tUUAMAwgFhhsbAx/Qkp+MFr1dZVPiEHFC55HmigZAZL+ssywQ ZVeyV/406CWy7I5w7X2I8yXExsCdeGSgXkcJ9tf6AGDZznVbYInyuDBRVACUwqT3vWmH toIJv+QkkuTq3svsgKR2nz2EYxtGKHAOtFtGh67In7ZYv3B69FkC01VxX/Dz8h6eZvKx kCPw==
MIME-Version 1.0
X-Received by 10.42.58.202 with SMTP id j10mr11225616ich.39.1359802052278; Sat, 02 Feb 2013 02:47:32 -0800 (PST)
Sender chris@rebertia.com
In-Reply-To <keipl5$kif$1@dont-email.me>
References <keipl5$kif$1@dont-email.me>
Date Sat, 2 Feb 2013 02:47:32 -0800
X-Google-Sender-Auth QIooZ_WonWtcw6P8edFzdafooIM
Subject Re: Floating point calculation problem
From Chris Rebert <clp2@rebertia.com>
Cc python-list@python.org
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQnqHRanNaVk09uQ0LSUGEOhNgPxb3WeNLB5C8ivsTXBub7wdGQSyiF3rA94050Q5QuPuYD3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1290.1359802060.2939.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1359802060 news.xs4all.nl 6889 [2001:888:2000:d::a6]:39642
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38067

Show key headers only | View raw


On Sat, Feb 2, 2013 at 2:27 AM, Schizoid Man <schiz_man@21stcentury.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 10:27 +0000
  Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 21:34 +1100
    Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:14 +0000
      Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:20 +1100
        Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:34 +0000
          Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:38 +1100
            Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:51 +0000
              Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-02 22:58 +1100
                Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 15:48 +0000
                Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 15:54 +0000
                Re: Floating point calculation problem Chris Angelico <rosuav@gmail.com> - 2013-02-03 03:00 +1100
                Re: Floating point calculation problem Michael Torrie <torriem@gmail.com> - 2013-02-02 11:19 -0700
                Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-03 12:25 +1100
                Re: Floating point calculation problem Dave Angel <d@davea.name> - 2013-02-02 21:20 -0500
                Re: Floating point calculation problem Michael Torrie <torriem@gmail.com> - 2013-02-02 21:22 -0700
              Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 23:11 +1100
      Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 22:45 +1100
        Re: Floating point calculation problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-02 11:50 +0000
  Re: Floating point calculation problem Chris Rebert <clp2@rebertia.com> - 2013-02-02 02:47 -0800
  Re: Floating point calculation problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-02 23:05 +1100

csiph-web