← 返回题库
中级

人民币转换

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve(____):
    cn_num = "____"
    cn_unit = ["____","____","____","____","____","____"]
    parts = str(____).split(____)
    yuan = int(____)
    cents_str = (parts[____] if len(____) > ____ else "____").ljust(____, "____")[:____]
    fen_total = yuan * ____ + int(____)
    if fen_total == ____:
        print(____)
        return
    digits = []
    for u in [____, ____, ____, ____, ____, ____, ____, ____]:
        digits.append(____)
        fen_total %= u
    # units对应: 千万/百万/十万/万/仟/佰/拾/个 -> 对应分的单位
    # 简化:按位处理
    amount_str = str(int(str(____).replace(____).ljust(len(str(____).split(____)[____])+____,"____")[:len(str(____).split(____)[____])+____]))
    # 重新实现
    parts2 = str(____).split(____)
    yuan2 = int(____)
    dec2 = (parts2[____] if len(____) > ____ else "____").ljust(____,"____")[:____]
    jiao = int(____)
    fen2 = int(____)
    result = "____"
    units2 = ["____","____","____","____"]
    y = yuan2
    yuan_digits = []
    for u in [____, ____, ____, ____]:
        yuan_digits.append(____)
        y %= u
    prev_zero = False
    wrote = False
    for idx, (____) in enumerate(zip(____)):
        if d != ____:
            if prev_zero and wrote:
                result += "____"
            result += cn_num[d] + u
            prev_zero = False
            wrote = True
        else:
            prev_zero = True
    if jiao:
        result += cn_num[jiao] + "____"
    if fen2:
        result += cn_num[fen2] + "____"
    print(____)

示例

输入
solve(123.45)
期望输出
人民币壹佰贰拾叁元肆角伍分
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码