X-Received: by 10.66.144.228 with SMTP id sp4mr1577579pab.5.1403160480704; Wed, 18 Jun 2014 23:48:00 -0700 (PDT) X-Received: by 10.50.60.7 with SMTP id d7mr79317igr.10.1403160480456; Wed, 18 Jun 2014 23:48:00 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!r2no4676420igi.0!news-out.google.com!gf2ni1igb.0!nntp.google.com!r2no4676415igi.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Wed, 18 Jun 2014 23:48:00 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=58.84.215.205; posting-account=_SqfYQoAAADKNDByavvb6bZJr50UfqXN NNTP-Posting-Host: 58.84.215.205 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <52ba65d1-a5dc-47b5-bccd-e05b24ae3e1f@googlegroups.com> Subject: Re: how to check if a value is a floating point or not From: Nicholas Cannon Injection-Date: Thu, 19 Jun 2014 06:48:00 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:73394 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 b= ut i am using the function isnumeric to check if the user has entered an in= t value. I need the same for floating point types so i could implement an o= r 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 happ= y 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 pos= sible 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 functio= n picks up the decimal as false. This means if the user inputs a float it h= as to be false. I then test if this input has any alphabetical characters i= f it does not the user could have only entered something like 12.5 oppose = to abc.d. This method works fine and it i have tested it and it works fine= . if incase this input did have a letter it would be picked up by the isalp= ha function. There is one annoying error doing it this way and that is if y= ou enter 12.ab or ab.12 it will say that it is okay. Still working on this = so this should get sorted out soon.