I've followed the directions indicated on this link using the method .isdigit()
to check if a string is a number, and it fails for me.
I am simply trying:
print("final weight:", weight)
if weight.isdigit() == True:
print("yes")
if weight.isdigit() == False:
print("weight is not a digit")
It prints:
final weight: 1,873
weight is not a digit
I am very confused why this fails because 1,873
is in fact a number.
UPDATE:
Using RegEx worked. I simply do:
regnumber = re.compile(r"(\d),(\d) | (\d)") #looks for numbers with commas and numbers without commas
if regnumber.search(weight):
print("weight = an int")