Detect Floating Point Number

Sort by

recency

|

529 Discussions

|

  • + 0 comments
    def isaFloat(string):
        try:
            if string == '0':
                return False
            float(string.strip())
            return True
        except ValueError:
            return False
            
    for nums in range(int(input())):
        print(isaFloat(input()))
    
  • + 0 comments
    import re
    T = int(input())
    N = [input() for _ in range(T)]
    for x in N:
        if re.match(r'^[+-]?\d*\.\d+$', x):
            print(True)
        else:
            print(False)
    
  • + 0 comments
    n = input()
    
    for i in range(int(n)):
        a = input()
        if a == '0' :
            print("False")
        else:
            try:
              float(a)
              print("True")
            except ValueError:
              print("False")
    
  • + 0 comments

    is it me or just an error that the following code doesn't work for string(0) (='0')

    I still dont get why it doesn't print out anything nor True, nor False. just nothing printed out for '0'

    import re
    
    T = int(input())
    for _ in range(T):
        string = str(input())
        try:
            if float(string):
                if re.match('([\\+\\-]?\d*\\.\d+)', string):
                    print(True)
        except Exception:
            print(False)
    
  • + 0 comments
    T = int(input())
    
    for k in range (T) :
        x = 1
        s = input()
        
        try :
            y = float (s)
            if s.count(".") == 0 :
                x *= 0
                
        except :
            x *= 0 
               
        print(bool(x))