We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Detect Floating Point Number
Detect Floating Point Number
Sort by
recency
|
545 Discussions
|
Please Login in order to post a comment
import re t=int(input()) pattern=r'^[+-]?\d*.\d+$' for _ in range(t): s=input() if re.match(pattern,s): print(True) else: print(False)
Adding try except passed all the test cases. It is needed for the constraint: "Number must not give any exceptions when converted using float(N)"
import re T = int(input()) pattern = r'^[+-]?\d*.\d+$'
for _ in range(T): N = input() try: num = float(N) match = re.search(pattern,N) print(bool(match)) except: print(False)
import re t = int(input()) for i in range(t): n = input() print(bool(re.match(r'^[+-]?\d*.\d+$', n)))
import re T = int(input().strip())
float_number_pattern = r"^[+-]?([0-9][.][0-9]+|[0-9]+[.][0-9])$"
for _ in range(0,T): string = input().strip() if re.match(float_number_pattern,string): print("True") else: print("False")