Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38068
| From | "Schizoid Man" <schiz_man@21stcentury.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Floating point calculation problem |
| Date | 2013-02-02 11:14 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <keisev$7v1$1@dont-email.me> (permalink) |
| References | <keipl5$kif$1@dont-email.me> <mailman.1289.1359801291.2939.python-list@python.org> |
"Chris Angelico" <rosuav@gmail.com> wrote in message
news:mailman.1289.1359801291.2939.python-list@python.org...
> On Sat, Feb 2, 2013 at 9:27 PM, Schizoid Man <schiz_man@21stcentury.com>
> 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.
Thanks for the reply. You're right - even in 2.7.3 if I toggle between
float(input(x)) and input(x), the result of the calculation changes. What
does the float cast do exactly?
> 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.
Scratch that, I'm not sure which result is right now, so need to look at the
full calculations in details. What would be the difference between
raw_input() and float(input())?
Thanks again.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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