Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73400

Re: how to check if a value is a floating point or not

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'else:': 0.03; 'float': 0.07; 'false,': 0.09; 'false.': 0.09; 'mixed': 0.09; 'parameter': 0.09; 'python': 0.11; 'def': 0.12; '*any*': 0.16; '*only*': 0.16; 'calculator': 0.16; 'inputs': 0.16; 'integer.': 0.16; 'oppose': 0.16; 'picks': 0.16; 'scripts.': 0.16; 'u+2155,': 0.16; 'vulgar': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'value.': 0.19; 'entered': 0.20; '>>>': 0.22; 'input': 0.22; 'tests': 0.22; 'either.': 0.24; 'fraction': 0.24; 'integer': 0.24; 'unicode': 0.24; 'source': 0.25; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'am,': 0.29; 'characters': 0.30; 'errors': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'decimal': 0.31; 'this.': 0.32; 'probably': 0.32; 'could': 0.34; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'false': 0.36; 'otherwise.': 0.36; 'possible': 0.36; 'implement': 0.38; 'thank': 0.38; 'checks': 0.38; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'users': 0.40; 'according': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'ian': 0.60; 'first': 0.61; 'you.': 0.62; 'making': 0.63; '8bit%:61': 0.84; 'characters,': 0.84; 'subject:check': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=a3tusg0bw4oAwVjYC78HpLTWJRGQ1BI41w3oZgV/ttQ=; b=0/9IbM+GYhdetQYz/l4PiwSIEHi0ipz7iFWdfkzXrgbY2iYhw1Y0iQAi8LULL7682F mVXnF7enK19d1D+7X5DBLp2THGUFb0C01oroA/TghJ3qoj6vkaBKWv39gDb93lFrqEGm IExFjv7+aRV53GlsbQx+V0dLzHODcOMO4xIuGxYRYt7ApMMFFeI25JSmmJ6B1X6SXJL8 TYKJjGyxMUYKR/OPT0QneUBliZybwf3qd3AOOzS9Gm12VsUCYlcFSbkmYKYeb5EcxUK0 OfW8Ps4VHliiTI2G5zXooEad6Tx037btNjugj8h2oRb5Ww1KSJhBibr4qqVn8JSXa5EA hNoA==
X-Received by 10.236.8.103 with SMTP id 67mr5020751yhq.29.1403163511749; Thu, 19 Jun 2014 00:38:31 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CALwzidmuiN3ch_6SO+s72kNZjwJjGTXdkkgRbCK9BqFpQ9q-ng@mail.gmail.com>
References <d5ca21d7-23e6-4240-83d8-262d0f877f7e@googlegroups.com> <52ba65d1-a5dc-47b5-bccd-e05b24ae3e1f@googlegroups.com> <CALwzidmuiN3ch_6SO+s72kNZjwJjGTXdkkgRbCK9BqFpQ9q-ng@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 19 Jun 2014 01:37:50 -0600
Subject Re: how to check if a value is a floating point or not
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11134.1403163519.18130.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1403163519 news.xs4all.nl 2962 [2001:888:2000:d::a6]:54529
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73400

Show key headers only | View raw


On Thu, Jun 19, 2014 at 1:23 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Thu, Jun 19, 2014 at 12:48 AM, Nicholas Cannon
> <nicholascannon1@gmail.com> wrote:
>> On Thursday, June 19, 2014 1:53:31 PM UTC+8, Nicholas Cannon wrote:
>>> I am making a calculator and i need it to support floating point values but i am using the function isnumeric to check if the user has entered an int value. I need the same for floating point types so i could implement an or in the if statement that checks the values the user has entered and allow it to check and use floating points. If you need the source code i am happy to give it to you. Thank you for your help
>>
>> I am using python 2.7.7 and i have come up with away but there is still possible errors for this. What i did was i this
>>
>> #checks if the user input is an integer value
>> def checkint(a):
>>         if a.isnumeric():
>>                 return True
>>         else:
>>                 if a.isalpha():
>>                         return False
>>                 else:
>>                         return True
>>
>> The parameter a is the users input by the raw_input function. I first test if it is normal int with the isnumeric function. Unfortunately this function picks up the decimal as false. This means if the user inputs a float it has to be false. I then test if this input has any alphabetical characters if it does not the user could have only entered  something like 12.5 oppose to abc.d.
>
> unicode.isalpha does not test if the input has *any* alphabetic
> characters.  It tests if the input is *only* alphabetic characters.
> u'12.5'.isalpha() does return False.  u'abc.d'.isalpha() *also*
> returns False, because the decimal point is not alphabetic.

Incidentally, unicode.isnumeric is probably not what you want either.
According to the docs, it returns "True if there are only numeric
characters in S, False otherwise. Numeric characters include digit
characters, and all characters that have the Unicode numeric value
property, e.g. U+2155, VULGAR FRACTION ONE FIFTH."  So that includes
strings like u'123⅕⅓Ⅷ٤', which is clearly not an integer.  You'd
likely do better with unicode.isdigit, and even then you'd be allowing
for mixed scripts.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to check if a value is a floating point or not nicholascannon1@gmail.com - 2014-06-18 22:53 -0700
  Re: how to check if a value is a floating point or not Gary Herron <gary.herron@islandtraining.com> - 2014-06-18 23:22 -0700
  Re: how to check if a value is a floating point or not Nicholas Cannon <nicholascannon1@gmail.com> - 2014-06-18 23:48 -0700
    Re: how to check if a value is a floating point or not Ben Finney <ben@benfinney.id.au> - 2014-06-19 17:19 +1000
    Re: how to check if a value is a floating point or not Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-19 01:23 -0600
    Re: how to check if a value is a floating point or not Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-19 01:37 -0600
  Re: how to check if a value is a floating point or not Sturla Molden <sturla.molden@gmail.com> - 2014-06-19 13:46 +0000
  Re: how to check if a value is a floating point or not Nicholas Cannon <nicholascannon1@gmail.com> - 2014-06-19 23:14 -0700
    Re: how to check if a value is a floating point or not Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-20 00:22 -0600
    Re: how to check if a value is a floating point or not Sturla Molden <sturla.molden@gmail.com> - 2014-06-20 13:16 +0000
    Re: how to check if a value is a floating point or not Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-06-20 14:40 +0100
      Re: how to check if a value is a floating point or not Grant Edwards <invalid@invalid.invalid> - 2014-06-20 14:28 +0000
        Re: how to check if a value is a floating point or not alister <alister.nospam.ware@ntlworld.com> - 2014-06-20 15:15 +0000
        Re: how to check if a value is a floating point or not Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-20 09:44 -0600

csiph-web