From d5ccfcc484f53c496c032a2a8133a81b3eac9f20 Mon Sep 17 00:00:00 2001 From: Besthope <874256269@qq.com> Date: Mon, 21 Oct 2024 14:46:24 +0800 Subject: [PATCH 1/2] fix: fixed middle --- lab0/lab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab0/lab.py b/lab0/lab.py index ca8710f..736ce3b 100644 --- a/lab0/lab.py +++ b/lab0/lab.py @@ -2,7 +2,7 @@ def middle(a, b, c): """Return the number among a, b, and c that is not the smallest or largest. Assume a, b, and c are all different numbers. """ - return ____ + return sorted([a, b, c])[1] def sum_digits(y: int) -> int: From 54add0e99e3e02cf0c6548a11801cc066dc730ee Mon Sep 17 00:00:00 2001 From: Besthope <874256269@qq.com> Date: Mon, 21 Oct 2024 14:47:01 +0800 Subject: [PATCH 2/2] feat: implement lab.py --- lab0/lab.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lab0/lab.py b/lab0/lab.py index 736ce3b..96c522d 100644 --- a/lab0/lab.py +++ b/lab0/lab.py @@ -9,11 +9,27 @@ def sum_digits(y: int) -> int: """ Sum all the digits of y. """ - pass + sum = 0 + while y > 0: + digit = y % 10 + y //= 10 + sum += digit + return sum def double_eights(n: int) -> bool: """ Return True if n has two eights in a row. """ - pass \ No newline at end of file + prev_eight = False + while n > 0: + digit = n % 10 + if digit == 8: + if prev_eight: + return True + else: + prev_eight = True + else: + prev_eight = False + n //= 10 + return False \ No newline at end of file