p1560是这样写吗?

def ensure(condition, message):
if condition:
print('*** 测试成功')
else:
print('*** 测试失败:', message)
def count_string(string, char):
a = 0
for i in range(len(string)):
if string[i] == char:
a = a + 1
return a
def test_count_string():
ensure(count_string('hello', 'l') == 2, 'test count string 1')
ensure(count_string('wonder', 'n') == 1, 'test count string 2')
ensure(count_string('wonder', 'h') == 0, 'test count string 3')

test_count_string()

1 条评论

  • 1