Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'float': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'calculator': 0.16; 'exception:': 0.16; 'forgiveness': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'value.': 0.19; 'entered': 0.20; 'header:User-Agent:1': 0.23; 'source': 0.25; 'pass': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'raise': 0.29; 'statement': 0.30; 'code': 0.31; 'could': 0.34; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'implement': 0.38; 'thank': 0.38; 'checks': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'you.': 0.62; 'making': 0.63; 'anything.': 0.68; 'float,': 0.84; 'subject:check': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Sturla Molden Subject: Re: how to check if a value is a floating point or not Date: Thu, 19 Jun 2014 13:46:52 +0000 (UTC) References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 112-76-11.connect.netcom.no User-Agent: NewsTap/4.0.1 (iPad) X-: 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403185631 news.xs4all.nl 2939 [2001:888:2000:d::a6]:57896 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73428 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 It's better to ask forgiveness than ask permission... You don't have to check anything. If the user enters something that cannot be coverted to a float, the function float() will raise an exception: try: x = float(value) except ValueError: # not a float pass Sturla