control structures and functions def get_string(messagename="string"default=noneminimum_length= maximum_length= )message +"if default is none else [{ }]format(defaultwhile truetryline input(messageif not lineif default is not nonereturn default if minimum_length = return "elseraise valueerror("{ may not be emptyformatname)if not (minimum_length <len(line<maximum_length)raise valueerror("{namemust have at least "{minimum_lengthand at most "{maximum_lengthcharactersformat**locals())return line except valueerror as errprint("error"errusing str format(with mapping unpacking this function has one mandatory argumentmessageand four optional arguments if default value is given we include it in the message string so that the user can see the default they would get if they just press enter without typing any text the rest of the function is enclosed in an infinite loop the loop can be broken out of by the user entering valid string--or by accepting the default (if givenby just pressing enter if the user makes mistakean error message is printed and the loop continues as usualrather than explicitly using key=value syntax to pass local variables to str format(with format string that uses named fieldswe have simply used mapping unpacking on the mapping returned by locals(to do this for us the user could also break out of the loopand indeed out of the entire programby typing ctrl+ --this would cause keyboardinterrupt exception to be raisedand since this is not handled by any of the program' exception handlerswould cause the program to terminate and print traceback should we leave such "loophole"if we don'tand there is bug in our programwe could leave the user stuck in an infinite loop with no way out except to kill the process unless there is very strong reason to prevent ctrl+ from terminating programit should not be caught by any exception handler notice that this function is not specific to the make_html_skeleton py program--it could be reused in many interactive programs of this type such reuse could be achieved by copying and pastingbut that would lead to main