设计一个程序，接受0到9999之间的数字并打印数字的口头表达。
def convert_to_spoken(num):
    if not num:
        return '零'
    
    if num > 9999:
        print('输入数字必须小于10000')
        return
    
    singles = {1: '一', 2: '二', 3: '三', 4: '四',
        5: '五', 6: '六', 7: '七', 8: '八',
        9: '九'
    }
    
    teens = {10: '十', 11: '十一', 12: '十二',
        13: '十三', 14: '十四', 15: '十五',
        16: '十六', 17: '十七', 18: '十八',
        19: '十九'
    }
    
    tens = {2: '二十', 3: '三十', 4: '四十', 5: '五十',
        6: '六十', 7: '七十', 8: '八十', 9: '九十',
    }
    
    # 根据数字长度创建步骤列表
    steps = [
        (' 千', 1000000), (' 百', 1000),
        ('', 0)
    ]
    
    # 将数字分为每3位一段
    digits = []
    while num > 0:
        r = num % 1000
        digits.insert(0, r)
        num //= 1000
    
    spoken_num = []
    # 将每个3位数字转换成口头表达
    for i, dig in enumerate(digits):
        if dig == 0:
            continue
        
        lbl, step = steps[i]
        a, b = divmod(dig, step)
        
        spoken_num.append(convert_to_spoken_3dig(a, b, 
            singles, teens, tens))
        spoken_num.append(lbl)
    
    return ' '.join(spoken_num)

def convert_to_spoken_3dig(a, b, singles, teens, tens):
    spoken_nums = []
    
    # 将百位转换成口头表达
    if a:
        spoken_nums.append(singles[a] + '百')
    
    # 将十位转换成口头表达
    if b:
        if b in singles:
            spoken_nums.append(singles[b])
        elif b in teens:
            spoken_nums.append(teens[b])
        else:
            t, o = divmod(b, 10)
            spoken_nums.append(tens[t])
            if o:
                spoken_nums.append(singles[o])
    
    return ' '.join(spoken_nums)