I am writing a code on the subject of engineering which requires the user to input several values which the program will then work with.
At the moment I have the following code:
while True:
strainx =input("Please enter a value for strain in the x-direction: ")
num_format = re.compile("^[1-9][0-9]*\.?[0-9]*")
isnumber = re.match(num_format,strainx)
if isnumber:
break
In simple terms I am trying to ask the user to enter a value for strainx which is a number. If the user enters anything other than a number then the question will be repeated until they enter a number. However, by using this method the code does not accept decimals and there will be instances where the user must enter a decimal. Is there any way around this?