aboutsummaryrefslogtreecommitdiff
path: root/challenge-287/sgreen/python/ch-2.py
blob: 87059a0873d10efb15a1937f8dffde15661eacc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3

import re
import sys


def valid_number(s: str) -> bool:
    """Check if the given string is a valid number.

    Args:
        s (str): The supplied string.

    Returns:
        bool: True if the string is a valid number, False otherwise.
    """
    return bool(re.search(r'^[+-]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][+-]?[0-9]+)?$', s))


def main():
    result = valid_number(sys.argv[1])
    print('true' if result else 'false')


if __name__ == '__main__':
    main()