From bda881d8523deb0f6662969cff59ec9a66dc39db Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 13 Nov 2023 14:23:48 +0100 Subject: [PATCH] vault backup: 2023-11-13 14:23:48 --- Algo/B2/Exercises/Imperative exercise.md | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Algo/B2/Exercises/Imperative exercise.md b/Algo/B2/Exercises/Imperative exercise.md index 2c47111..16a2a64 100644 --- a/Algo/B2/Exercises/Imperative exercise.md +++ b/Algo/B2/Exercises/Imperative exercise.md @@ -8,6 +8,34 @@ def sum_digits (n: int) -> int: b = (n//10)%10 c = n%10 return (a+b+c) + +def product_digits (n): + a = n//10 + b = (n//10) % 10 + c = n % 10 + return (a*b*c) + +def abs (n): + if n > 0: + return n + else: + return (-1)*n + +def loop (n): + n = abs(n) + if (sum_digits(n) == product_digits(n)): + return n + else + return loop(n+1) ``` ## Exercise 2: +```python +def max3 (x: int, y: int, z: int) -> int: + if ((x > y) and (x > z)): + m = x + elif ((y > x) and (y > z)): + m = y + elif ((z > x) and (z > y)): + m = z + return m \ No newline at end of file