rapid introduction to procedural programming given the command line sum py data\sum dat (where the sum dat file contains list of numbers one per line and is in the examplesdata subdirectory)the output to the console istype integerseach followed by enteror ^ or ^ to finish count total mean we have made several small changes to make the program more suitable for use both interactively and using redirection firstwe have changed the termination from being blank line to the eof character (ctrl+ on unixctrl+zenter on windowsthis makes the program more robust when it comes to handling input files that contain blank lines we have stopped printing prompt for each number since it doesn' make sense to have one for redirected input and we have also used single try block with two exception handlers notice that if an invalid integer is entered (either via the keyboard or due to "badline of data in redirected input file)the int(conversion will raise valueerror exception and the flow of control will immediately switch to the relevant except block--this means that neither total nor count will be incremented when invalid data is encounteredwhich is exactly what we want we could just as easily have used two separate exception-handling try blocks insteadwhile truetryline input(if linetrynumber int(lineexcept valueerror as errprint(errcontinue total +number count + except eoferrorbreak but we preferred to group the exceptions together at the end to keep the main processing as uncluttered as possible piece # creating and calling functions |it is perfectly possible to write programs using the data types and control structures that we have covered in the preceding pieces howeververy often we want to do essentially the same processing repeatedlybut with small differencesuch as different starting value python provides means of encapsu