Floating point calculation problem
clp2 at rebertia.com
Sat Feb 2 11:47:32 CET 2013
On Sat, Feb 2, 2013 at 2:27 AM, Schizoid Man <schiz_man at 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: "))
> 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
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.
More information about the Python-list