From 03a380580d16525cae1da43773e5f10f9faf8e62 Mon Sep 17 00:00:00 2001 From: Nkosingiphile Lindani Sukati Date: Tue, 14 Oct 2025 21:14:24 +0200 Subject: [PATCH] Add files via upload --- main.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 56e2fb3..571b2d4 100644 --- a/main.py +++ b/main.py @@ -12,8 +12,12 @@ return [0, 1, 1] """ def fibonacci(n: int) -> list[int]: - - return [] + if n <= 0: + return [] #negative or zero return empty list + fib = [0,1] # starting with the first two numbers + while len(fib) < n: # generating a sequence until n terms + fib.append(fib[-1] + fib[-2]) + return fib[:n] #slice in case n is equal to 1 so we only return [0] """ @@ -25,7 +29,11 @@ def fibonacci(n: int) -> list[int]: return [2, 4, 8, 22, 50, 98] """ def even(nums: list[int]) -> list[int]: - return [] + evens = [] + for num in nums: + if num % 2 == 0: + evens.append(num) + return sorted(even) """ @@ -37,8 +45,11 @@ def even(nums: list[int]) -> list[int]: return [27, 17, 3, 1] """ def odd(nums: list[int]) -> list[int]: - - return [] + odds =[] + for num in nums: + if num % 2 != 0: + odds.append(num) + return sorted(odds, reverse = True) """ @@ -54,6 +65,11 @@ def odd(nums: list[int]) -> list[int]: sum(odd) = 4, sum(even) = 2 → returns 'Odd' """ def even_vs_odd(nums: list[int]) -> str: + # I think I’ll need to loop through the list and separate even and odd numbers. + # Then I can find the sum of all even numbers and the sum of all odd numbers. + # After that, I can use conditionals to compare which sum is greater. + # If both sums are the same, I should return "Tie". + # Still trying to figure out the best way to handle empty lists and edge cases. return "" @@ -71,7 +87,7 @@ def even_vs_odd(nums: list[int]) -> str: """ def is_prime(n): return False - +#I'm still learning about ValueError and hot to handle it and check prime numbers """ This function takes in a fullname, short year, @@ -86,4 +102,7 @@ def is_prime(n): - Look at the pattern of the example carefully. """ def generate_email(fullname: str, year: str, campus: str) -> str: - return "" +# I think this one will require string slicing and using parts of the first +# and last name. I noticed the examples take some letters from both names. +# Still figuring out how to pattern-match it correctly. + return "" \ No newline at end of file