# average4a.py # From Zelle's average4.py but with exception handling for no numbers input # # Average numbers using a sentinal loop (a while loop with a sentinal) # Use EOF as the sentinal (EOF is End Of File special value) # def main(): sum = 0.0 count = 0 xStr = raw_input("Enter a number ( to quit): ") # priming the loop while xStr != "": x = eval(xStr) sum = sum + x count = count + 1 xStr = raw_input("Enter a number ( to quit): ") try: print"\nAverage is: ", sum/count except ZeroDivisionError: print "You must enter at least one number" main()