![]() |
Re: Floating point calculation problem
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 |
| All times are GMT. The time now is 12:03 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.