Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'float': 0.05; 'dynamically': 0.07; 'line:': 0.07; 'python': 0.09; 'incorrect': 0.09; 'least)': 0.09; 'typed': 0.09; '(the': 0.15; 'passing': 0.15; 'sat,': 0.15; '2.7.3?': 0.16; 'former,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; '(in': 0.18; 'input': 0.18; 'feb': 0.19; 'bit': 0.21; 'subject:problem': 0.22; 'this:': 0.23; 'header:In-Reply- To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; '"the': 0.29; 'this.': 0.29; 'returned': 0.30; 'error': 0.30; 'function.': 0.33; 'rid': 0.33; 'to:addr:python-list': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'method': 0.36; 'does': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'most': 0.61; 'cast': 0.65; 'dangerous': 0.66; '2013': 0.84; 'casting': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=uOias9iVeEZj9pVa5tqSxQNEaZZBus/a1jmccgeKNo8=; b=FrZzvFf/WYlXlqI4vvEibQYI2HaBo+b1nFuqSywDotCe9rFx2B2lNv2gCNUVsPteQ7 mzQzRmJr4qedF4Z5o6Szif5dyguxpEx5A4HSjya2ABhH31sNLhvBtyoGEIBJAcK9UUwd G0grriyQ70k2KGYb610o8hfiM7TTRo4I3by+o9oW/qGD+8DQHXITfbs6xkxcG93wbWMT bfdFtsHuOIwQFqpiWOA8xB31V1hvtL00MprPwwkwQO89XD1Hwn11LDgCygGIf0mIafFx akNKyeNRg7w0i+Xj1tA3PmvTsrmpCrHCqGAv738VD6SLvxM+gS9h9J2Sn+AjpbFJopB1 +nyw== MIME-Version: 1.0 X-Received: by 10.224.186.83 with SMTP id cr19mr15591964qab.51.1359801282996; Sat, 02 Feb 2013 02:34:42 -0800 (PST) In-Reply-To: References: Date: Sat, 2 Feb 2013 21:34:42 +1100 Subject: Re: Floating point calculation problem From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359801291 news.xs4all.nl 6958 [2001:888:2000:d::a6]:36289 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38066 On Sat, Feb 2, 2013 at 9:27 PM, Schizoid Man wrote: > 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: ")) > > However, then the result returned by the method is wrong. Why does this > error occur in version 3.3.0 but not in 2.7.3? Why is the result incorrect > when s is cast as a float (the casting is not required in 2.7.3)? How is > Python dynamically typed if I need to cast (in version 3.3.0 at least) to > get rid of the compile error? Did you use input() or raw_input() in 2.7.3? If the former, you were actually doing this: s = eval(input("Enter s: ")) That's extremely dangerous and inadvisable, so it's better to go with 3.3 or the raw_input function. Passing it through float() is, most likely, the right way to do this. But what do you mean by "the result... is wrong"? That's the bit to look into. ChrisA