Header Ad

HackerRank Detect Floating point number solution in python

In Detect floating-point number problem You are given a string N. Your task is to verify that N is a floating-point number.

HackerRank Detect Floating point number solution in python


Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT

import re

for k in range(int(raw_input())):
    print bool(re.match(r"^[+-]?([0-9]+)?.[0-9]+$",raw_input()))



Problem solution in Python 3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
for _ in range(int(input())):
    print(re.search(r'^([-\+])?\d*\.\d+$', input()) is not None)


Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re 

for _ in xrange(int(raw_input())):
    print bool(re.search(r"^[+-]?[0-9]*\.[0-9]+$", raw_input().strip()))


Problem solution in pypy3 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
n= int(input())
numbers = []
for i in range(n):
    i = input()
    numbers.append(i)
#print(len(numbers))
for i in numbers:
    print(bool(re.search(r'^[-+]?[0-9]*\.[0-9]+$',i)))


Post a Comment

0 Comments