Detect Floating Point Number

Sort by

recency

|

538 Discussions

|

  • + 0 comments

    t = int(input()) for i in range(t): a=input() try: if float(a): print(True) else: print(False) except: print(False)

  • + 0 comments
    import re
    
    N = int(input())
    
    input_list = [ input() for i in range(N)]
    
    for i in input_list:
        if re.match(r"^[+-]?(\d)*(\.)(\d)*$", i):
            print("True")
        else:
            print("False")
    
  • + 0 comments
    import re
    
    n = int(input())
    cases = [input() for i in range(n)]
    
    pattern = r"^[+-]?\d*\.\d+$"
    result = [bool(re.match(pattern, c)) for c in cases]
    
    for r in result:
        print(r)
    
  • + 0 comments

    I believe this works well enough! As pythonic as I could make it.

    import re
    
    N=int(input())
    pattern=r"^[+-]?\d*\.\d+$"
    
    for i in range(N):
        num=input()
        print(bool(re.match(pattern, num)))
    
  • + 1 comment

    Most Easy to understood

    t=int(input())
    lis=[]
    for i in range(t):
        lis.append(input())
    
    for item in lis:
        try:
            if float(item):
                print(True)
            else:
                print(False)
        except:
            print(False)