Fix error message and format with python/black (#1025)

@SandersLin Your review please?
This commit is contained in:
cclauss 2019-07-16 07:26:28 +02:00 committed by Anup Kumar Panwar
parent 1e55bfd4da
commit 2fb3beeaf1

View File

@ -1,3 +1,6 @@
#!/usr/bin/env python3
def climb_stairs(n: int) -> int: def climb_stairs(n: int) -> int:
""" """
LeetCdoe No.70: Climbing Stairs LeetCdoe No.70: Climbing Stairs
@ -17,11 +20,23 @@ def climb_stairs(n: int) -> int:
3 3
>>> climb_stairs(1) >>> climb_stairs(1)
1 1
>>> climb_stairs(-7) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AssertionError: n needs to be positive integer, your input -7
""" """
assert isinstance(n,int) and n > 0, "n needs to be positive integer, your input {0}".format(0) fmt = "n needs to be positive integer, your input {}"
if n == 1: return 1 assert isinstance(n, int) and n > 0, fmt.format(n)
if n == 1:
return 1
dp = [0] * (n + 1) dp = [0] * (n + 1)
dp[0], dp[1] = (1, 1) dp[0], dp[1] = (1, 1)
for i in range(2, n + 1): for i in range(2, n + 1):
dp[i] = dp[i - 1] + dp[i - 2] dp[i] = dp[i - 1] + dp[i - 2]
return dp[n] return dp[n]
if __name__ == "__main__":
import doctest
doctest.testmod()