diff --git a/intro/Task102.py b/intro/Task102.py new file mode 100644 index 0000000..a42657f --- /dev/null +++ b/intro/Task102.py @@ -0,0 +1,2 @@ +def add_three_numbers(x: int, y: int, z: int) -> int: + return x + y + z diff --git a/intro/Task103.py b/intro/Task103.py new file mode 100644 index 0000000..ee4427c --- /dev/null +++ b/intro/Task103.py @@ -0,0 +1,5 @@ +def probability(x: float) -> float: + if 0 <= x <= 1: + return x + else: + return 0 \ No newline at end of file diff --git a/intro/Task104.py b/intro/Task104.py new file mode 100644 index 0000000..7c9ad9e --- /dev/null +++ b/intro/Task104.py @@ -0,0 +1,4 @@ +def fahrenheit(x: float) -> float: + if x < -273.15: + return -459.67 + return x * (9/5) + 32 \ No newline at end of file diff --git a/intro/Task105.py b/intro/Task105.py new file mode 100644 index 0000000..3ae6714 --- /dev/null +++ b/intro/Task105.py @@ -0,0 +1,8 @@ +def is_almost_prime(number: int, limit: int) -> bool: + if number < 0: + return False + else: + for i in range(2, limit+1): + if number % i == 0: + return False + return True diff --git a/intro/Task106.py b/intro/Task106.py new file mode 100644 index 0000000..a100a52 --- /dev/null +++ b/intro/Task106.py @@ -0,0 +1,5 @@ +def penultimate(l: list, otherwise: object) -> object: + if (not l) or (len(l) == 1): + return otherwise + else: + return l[-2] \ No newline at end of file diff --git a/intro/Task107.py b/intro/Task107.py new file mode 100644 index 0000000..759c80d --- /dev/null +++ b/intro/Task107.py @@ -0,0 +1,11 @@ +def list_cubed(l: list) -> object: + if not l: + return 0 + + sum = 0 + + for i in range(l): + sum = sum + (i*i*i) + + return sum +