Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'float': 0.07; 'python3': 0.07; 'string': 0.09; 'indicates': 0.09; 'indication': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'calculator': 0.16; 'valid.': 0.16; 'wrote:': 0.18; 'value.': 0.19; 'entered': 0.20; 'header :User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'source': 0.25; 'mention': 0.26; 'received:(smtp server)': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'characters': 0.30; 'statement': 0.30; 'code': 0.31; 'gary': 0.31; 'could': 0.34; 'except': 0.35; 'something': 0.35; 'convert': 0.35; 'test': 0.35; 'but': 0.35; 'implement': 0.38; 'represent': 0.38; 'thank': 0.38; 'checks': 0.38; 'easiest': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'catch': 0.60; 'failures': 0.60; 'you.': 0.62; 'making': 0.63; 'email addr:gmail.com': 0.63; 'such': 0.63; 'invalid': 0.68; 'float,': 0.84; 'subject:check': 0.84; 'wishing': 0.93 X-Virus-Scanned: OK Date: Wed, 18 Jun 2014 23:22:55 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: how to check if a value is a floating point or not References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403159518 news.xs4all.nl 2891 [2001:888:2000:d::a6]:57937 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73393 On 06/18/2014 10:53 PM, nicholascannon1@gmail.com 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 Your mention of *isnumeric* indicates to me that you are using Python3 (correct?) and are wishing to test if a *string* contains characters that represent an int or a float (correct?). The easiest way to test such is to just try to convert it to an int or float, and catch failures as an indication that it is not valid. Something like: try: value = float(s) except ValueError: ... handle invalid string ... Gary Herron