[Solved] Basic Error Capture – for inputs – Python [closed]


Would this help?

totalReTries = 10
acquiredValue = None
PROMPT_MESSAGE = "Please enter the valid value: "
typeOfInteredData = float
rangeOfData = range(10, 20)

for currentRetry in range(1, totalReTries):

    print "Attempt %d of %d" % (currentRetry, totalReTries)
    try:
        acquiredValue = input(PROMPT_MESSAGE)
    except ValueError:
        print("Incorrect data format. Please try again.")
        continue

    if type(acquiredValue) != typeOfInteredData:
        print "Incorrect data type. Please try again."
        continue
    elif not acquiredValue in rangeOfData:
        print "Incorrect data Range. Please try again."
        continue
    break

if not acquiredValue:
    print "ERROR: Failed to get a correct value"
else:
    print "The acquired value is: " + str(acquiredValue)

Adapting this into a function, as suggested above, would be a good idea too.
Regards

solved Basic Error Capture – for inputs – Python [closed]