-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidNumber.py
More file actions
22 lines (16 loc) · 828 Bytes
/
Copy pathvalidNumber.py
File metadata and controls
22 lines (16 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# TODO: In practically all automation scenarios as we perform measurements of Device under Test (DUT), we query equipment (instruments) for different values (center frequency, voltage, current and so on). In general the queries can be even to a service that return some number as a string.
# Assume that as a result of your query you get a string that represents a number.
# For example, it could be “5” for 5 Volts measured by a multimeter.
# Please, help me to write a function that checks if a given string as a valid number.
import re
def isNumber(str):
pattern = r'^[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?$'
return re.match(pattern, str) is not None
def isNumber(str):
return str.isdigit()
def isNumber(str):
try:
float(str)
return True
except ValueError:
return False