# Copyright (c) 2017 The Regents of the University of Michigan.
# All Rights Reserved. Licensed according to the terms of the Revised
# BSD License. See LICENSE.txt for details.

class LuhnNumber:

    def __init__ (self, number = None):
        if number is None:
            self.number = None

        else:
            try:
                self.number = int(number)

            except ValueError:
                self.number = None

    def __bool__ (self):
        return self.number == 0

    def __repr__ (self):
        return "<{} {}>".format(self.__class__.__name__,
                                repr(self.number))

def is_luhn_checkable (number):
    if isinstance(number, str):
        return bool(number)

    else:
        return isinstance(number, int)

def rotate_digit (digit):
    result = digit * 2
    return result if result < 10 else result - 9

def add_two_digits (two_digits):
    first_digit = two_digits // 10
    second_digit = two_digits % 10

    return first_digit + rotate_digit(second_digit)

def get_check_digit_from_checkable_int (number):
    total = 0

    while number > 0:
        total += add_two_digits(number % 100)
        number //= 100

    return (9 * total) % 10

def get_check_digit_if_convertable_to_int (number):
    try:
        return get_check_digit_from_checkable_int(int(number))

    except ValueError:
        return None

def get_check_digit (number = None):
    if is_luhn_checkable(number):
        return get_check_digit_if_convertable_to_int(number)

    else:
        return None

def convert_to_int (number):
    try:
        return int(number)

    except ValueError:
        return 1

def verify_check_digit (number = None):
    if is_luhn_checkable(number):
        number = convert_to_int(number)

        return number % 10 == get_check_digit(number // 10)

    else:
        return False

@@ -246,22 +246,31 @@
  if 
+isinstance(
 number
+,
  i
-s None
+nt)
 :%0A  
@@ -289,28 +289,30 @@
 lf.number = 
-None
+number
 %0A%0A        el
@@ -315,33 +315,36 @@
   el
-se:%0A            try
+if isinstance(number, str)
 :%0A
-    
     
@@ -360,65 +360,64 @@
 elf.
-number = int(number)%0A%0A            except ValueError:%0A    
+__try_to_extract_number_from_str(number)%0A%0A        else:%0A
     
@@ -636,16 +636,184 @@
 mber))%0A%0A
+    def __try_to_extract_number_from_str (self, number):%0A        try:%0A            self.number = int(number)%0A%0A        except ValueError:%0A            self.number = None%0A%0A
 def is_l

Replace nested condition-and-try-catch with switch