def format_number(num): # # Is the string the correct length? # if len(num) != 10: return "" # # Are there any characters that aren't digits? # for ch in num: if ch < "0" or ch > "9": return "" # # Use string slices to get the portions of the number that we need # return "(" + num[0:3] + ") " + num[3:6] + "-" + num[6:10]