Discuss / Python / 还是学的没到位。。。

还是学的没到位。。。

Topic source

忽略略略

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

-- coding: utf-8 --

def product(numbers): if len(numbers) == 0: raise TypeError ('错误') p=1 for n in numbers: p = pn return p
print('product(5) =', product(5)) print('product(5, 6) =', product(5, 6)) print('product(5, 6, 7) =', product(5, 6, 7)) print('product(5, 6, 7, 9) =', product(5, 6, 7, 9)) if product(5) != 5: print('测试失败!') elif product(5, 6) != 30: print('测试失败!') elif product(5, 6, 7) != 210: print('测试失败!') elif product(5, 6, 7, 9) != 1890: print('测试失败!') else: try: product() print('测试失败!') except TypeError: print('测试成功!')

忽略略略

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

复制进去就没*号了???

悭臾_X07365

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

转义啊,星号前面加个反斜杠


  • 1

Reply