On 10/02/17 19:15, Peter Pearson wrote:
> On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron <a...@phpandmore.net>
wrote:
>> Use:
>>
>> try:
>> num=int(str)
>> except ValueError e:
>> print "Error: not an integer"
>
> What should happen if the user types "1.0"?
>
> To be flexible about this possibility, you could accept the number
> as a float, and then complain if int(num) != num.
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.99999999999999995
1.0
>>> f = float("0.99999999999999995")
>>> i = int(f)
>>> i
1
>>> f
1.0
>>> i == f
True
>>>
E.
--
https://mail.python.org/mailman/listinfo/python-list