Python Forum
Python Calculator Application
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Calculator Application
#3
(Jul-21-2017, 04:23 PM)MemeStealer Wrote:
def checkIfInt(possibleInt):
   try:
       val = int(possibleInt)
       return True
   except ValueError:
       return False

What about str.isdigit()?
def checkIfInt(possibleInt):
    return possibleInt.isdigit()

>>> checkIfInt("42")
True
>>> checkIfInt("k13")
False
>>> checkIfInt("8.4")
False
As snippsat pointed out, the operator module could make things much cleaner for you: https://docs.python.org/3/library/operator.html
Reply


Messages In This Thread
Python Calculator Application - by MemeStealer - Jul-21-2017, 04:23 PM
RE: Python Calculator Application - by snippsat - Jul-21-2017, 06:03 PM
RE: Python Calculator Application - by MemeStealer - Jul-21-2017, 07:08 PM
RE: Python Calculator Application - by MemeStealer - Jul-21-2017, 07:12 PM
RE: Python Calculator Application - by nilamo - Jul-21-2017, 06:36 PM
RE: Python Calculator Application - by nilamo - Jul-21-2017, 07:08 PM
RE: Python Calculator Application - by MemeStealer - Jul-21-2017, 08:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some help trying to get my Python mortgage amortization calculator to work prope IamSirAskAlot 4 17,269 Feb-12-2024, 10:53 PM
Last Post: BerniceBerger
  Python running only in application Mawixy 2 1,781 Apr-19-2022, 11:38 AM
Last Post: Mawixy
  New to python, trying to make a basic calculator AthertonH 2 1,835 Apr-14-2022, 03:33 PM
Last Post: AthertonH
  How To Create A "Birthday Calculator" in Python? unigueco9 3 6,461 Oct-11-2021, 08:03 PM
Last Post: SamHobbs
  How to send data from a python application to an external application aditya_rajiv 1 2,981 Jul-26-2021, 06:00 AM
Last Post: ndc85430
  python calculator only using decomposing functions kirt6405 1 2,374 Jun-19-2021, 12:52 AM
Last Post: bowlofred
  python application and credentials safety concern aster 4 4,552 Mar-06-2021, 06:51 PM
Last Post: snippsat
  Keep Application running after Python script ends PEGylated_User 0 2,633 Nov-12-2020, 03:27 PM
Last Post: PEGylated_User
  Installing Python Application pplgf 3 3,373 Apr-27-2020, 10:51 PM
Last Post: Larz60+
  loop in pyautogui (python automation GUI application) pyprogrammer 0 5,505 Feb-12-2020, 02:52 PM
Last Post: pyprogrammer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020