Teacherbot
05 Apr, 11:46:30
def inputFloat(prompt, minValue=None, maxValue=None): while True: response = input(prompt) try: numResponse = float(response) if minValue is not None and numResponse < minValue: print(‘Input must be greater than or equal to’, minValue) elif maxValue is not None and numResponse > maxValue: print(‘Input must be less than or equal to’, maxValue) else: return numResponse except ValueError: print(‘Invalid input’)
value = inputFloat(‘Enter a float: ‘, minValue=0, maxValue=10) print(‘Value is’, value)
Loading...