Detect Floating Point Number

Sort by

recency

|

533 Discussions

|

  • + 0 comments
    import sys, re
    
    N = sys.stdin.read()
    N = N.splitlines()[1:]
    
    pattern = r"^[+-.]?\d*[.]\d+$"
    
    for line in N:
        match = re.search(pattern, line)
        if match != None:
            print('True')
        else:
            print('False')
    
  • + 0 comments
    import re
    pattern = r'^[+-\.]?[0-9]{0,}\.[0-9]{1,}$'
    n = int(input().strip())
    for _ in range(n):
        print( bool(re.match(pattern, input().strip())) )
    
  • + 0 comments
    import re
    for i in range(int(input())):
        number = input()
        print(bool(re.search('^[+-]?[0-9]{0,}\.[0-9]+[^A-Z]?$', number)))
    
  • + 0 comments
    import re
    
    num_test = int(input())
    pattern = re.compile(r'[-+]?\d*\.\d+')
    
    for _ in range(num_test):
        print(bool(pattern.fullmatch(input())))
    
  • + 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()))