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


Groups > comp.lang.python > #73399

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!newsfeed1a.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; 'parameter': 0.09; 'python': 0.11; 'def': 0.12; '*any*': 0.16; '*only*': 0.16; 'calculator': 0.16; 'fails.': 0.16; 'inputs': 0.16; 'oppose': 0.16; 'picks': 0.16; 'reinvent': 0.16; 'exception': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'value.': 0.19; 'entered': 0.20; 'input': 0.22; 'tests': 0.22; 'integer': 0.24; 'source': 0.25; 'second': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'am,': 0.29; 'characters': 0.30; 'converting': 0.30; 'errors': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'decimal': 0.31; 'gary': 0.31; 'this.': 0.32; 'could': 0.34; 'knows': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'false': 0.36; 'possible': 0.36; 'implement': 0.38; 'thank': 0.38; 'checks': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'users': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'catch': 0.60; 'first': 0.61; 'you.': 0.62; 'making': 0.63; 'subject:check': 0.84; 'you;': 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=us1chV5fYAN30V6+X4EFHKUzp0svwcKCJAq3dBHNqOs=; b=zb9izGouGGqsA/JUOJ8L8zWtKTsg9csWJ4VXWzO9GLcIGlntjtnLJGx/4W/7jbXiri VDOcCu/zoWnWXLzK4QiauI6qN7adLhVuVuuWbHaO4CpTM4vGv5C/OUbFBWecF3DWMY1D 2RpTUbOaPYASC+cPp8fGzFVnltHksi0U55tzNYgy4Hjq6NIyTqTGyBTSQfSGeBGcS1ys 1UsYcHMwubpjK2VVSXxUu+YxkqQ/GAc1ZXCzoZy0cq76WqXVTkR4JzmQ3WgZ5pDgTijm 96koqwY29xe9sqYzw4nYiSoyCUW11YU2sItvvVU7dpQEoQ2Y6ktARvDSs/qQu4AvQxf/ Yywg==
X-Received by 10.236.154.136 with SMTP id h8mr4714007yhk.105.1403162643369; Thu, 19 Jun 2014 00:24:03 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <52ba65d1-a5dc-47b5-bccd-e05b24ae3e1f@googlegroups.com>
References <d5ca21d7-23e6-4240-83d8-262d0f877f7e@googlegroups.com> <52ba65d1-a5dc-47b5-bccd-e05b24ae3e1f@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 19 Jun 2014 01:23:23 -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.11133.1403162953.18130.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1403162953 news.xs4all.nl 2971 [2001:888:2000:d::a6]:51721
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73399

Show key headers only | View raw


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.

I second Gary Herron's suggestion to just try converting the value and
catch the exception if it fails.  Python already knows how to do this
for you; there's no need to reinvent the wheel.

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