fork download
  1. def mul(x,*y):
  2. for n in y:
  3. x=x*n
  4. return x
  5.  
  6. # 测试
  7. print('mul(5) =', mul(5))
  8. print('mul(5, 6) =', mul(5, 6))
  9. print('mul(5, 6, 7) =', mul(5, 6, 7))
  10. print('mul(5, 6, 7, 9) =', mul(5, 6, 7, 9))
  11. if mul(5) != 5:
  12. print('mul(5)测试失败!')
  13. elif mul(5, 6) != 30:
  14. print('mul(5, 6)测试失败!')
  15. elif mul(5, 6, 7) != 210:
  16. print('mul(5, 6, 7)测试失败!')
  17. elif mul(5, 6, 7, 9) != 1890:
  18. print('mul(5, 6, 7, 9)测试失败!')
  19. else:
  20. try:
  21. mul()
  22. print('mul()测试失败!')
  23. except TypeError:
  24. print('测试成功!')
Success #stdin #stdout 0.08s 14188KB
stdin
Standard input is empty
stdout
mul(5) = 5
mul(5, 6) = 30
mul(5, 6, 7) = 210
mul(5, 6, 7, 9) = 1890
测试成功!