tool for coding logic in scripts in its full formit consists of the word if followed by test and an associated block of codeone or more optional elif ("else if"tests and code blocksand an optional else partwith an associated block of code at the bottom to serve as default python runs the block of code associated with the first test that is trueworking from top to bottomor the else part if all tests are false the ifelifand else parts in the preceding example are associated as part of the same statement because they all line up vertically ( share the same level of indentationthe if statement spans from the word if to the start of the print statement on the last line of the script in turnthe entire if block is part of the while loop because all of it is indented under the loop' header line statement nesting like this is natural once you get the hang of it when we run our new scriptits code catches errors before they occur and prints an error message before continuing (which you'll probably want to improve in later release)but "stopstill gets us outand valid numbers are still squaredenter text: enter text:xyz bad!bad!bad!bad!bad!bad!bad!badenter text: enter text:stop handling errors with try statements the preceding solution worksbut as you'll see later in the bookthe most general way to handle errors in python is to catch and recover from them completely using the python try statement we'll explore this statement in depth in part vii of this bookbut as previewusing try here can lead to code that some would see as simpler than the prior versionwhile truereply input('enter text:'if reply ='stop'break trynum int(replyexceptprint('bad! elseprint(num * print('bye'this version works exactly like the previous onebut we've replaced the explicit error check with code that assumes the conversion will work and wraps it in an exception handler for cases when it doesn' in other wordsrather than detecting an errorwe simply respond if one occurs quick exampleinteractive loops