Discuss / Python / 交作业来了

交作业来了

Topic source

来交作业了

# -*- coding: utf-8 -*-def mul(*args):
    result = 1    if len(args) == 0:
        raise TypeError(r"Can't be empty")
    else:
        for i in args:
            result = i*result
        return result


# 测试print('mul(5) =', mul(5))
print('mul(5, 6) =', mul(5, 6))
print('mul(5, 6, 7) =', mul(5, 6, 7))
print('mul(5, 6, 7, 9) =', mul(5, 6, 7, 9))
if mul(5) != 5:
    print('测试失败!')
elif mul(5, 6) != 30:
    print('测试失败!')
elif mul(5, 6, 7) != 210:
    print('测试失败!')
elif mul(5, 6, 7, 9) != 1890:
    print('测试失败!')
else:
    try:
        mul()
        print('测试失败!')
    except TypeError:
        print('测试成功!')

Dr.可以嘛

#2 Created at ... [Delete] [Delete and Lock User]
result = 1if len(args) == 0:    raise TypeError(r"Can't be empty")else:    for i in args:        result = i*result

请问这里是什么意思,有点不懂

向左走

#3 Created at ... [Delete] [Delete and Lock User]

如果没有输入参数就提示 

Can't be empty

  • 1

Reply