def print_reciprocal(num): '''Prints the reciprocal of num.''' recip = 1.0 / num print('Reciprocal of {0} is {1}'.format(num, recip)) def print_reciprocal_v2(num): '''Prints the reciprocal of num.''' try: recip = 1.0 / num except ZeroDivisionError: print('can\'t divide by zero') except TypeError: print('{0} isn\'t a valid number'.format(num)) else: print('Reciprocal of {0} is {1}'.format(num, recip))