From 83dbf5725951c58bf2942396c3c0af32d5690855 Mon Sep 17 00:00:00 2001 From: cemzajhb025 Date: Fri, 17 Oct 2025 12:59:58 +0200 Subject: [PATCH 1/4] test --- student_code.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/student_code.py b/student_code.py index d7fdfd0..07a5d3c 100644 --- a/student_code.py +++ b/student_code.py @@ -12,7 +12,13 @@ def sum_of_squares(n: int): Raises: ValueError: If n is a negative integer. """ - pass + try: + sum = 0 + for i in range(1, n + 1): + sum += i **2 + return sum + except ValueError: + return f"Enter a postive number" def evaluate_performance(grades: list, min_pass: int): """ @@ -25,7 +31,15 @@ def evaluate_performance(grades: list, min_pass: int): Returns: str: "Pass" if the average grade is greater than or equal to min_pass, otherwise "Fail". """ - pass + count = 0 + + for i in grades: + count += i + + if count/len(grades) >= min_pass: + return f"pass" + else: + return f"fail" def calculate_cumulative_performance(scores: dict): """ @@ -37,7 +51,20 @@ def calculate_cumulative_performance(scores: dict): Returns: dict: A dictionary containing the average score and a list of subjects where the score is below average. """ - pass + average_score = 0 + my_dict = {} + list_below_average = [] + for x, y in scores.items(): + average_score += y + average_score = average_score/len(scores) + + for x, y in scores.items(): + if y < average_score: + list_below_average.append(x) + + my_dict[average_score] = list_below_average + + return my_dict def analyze_improvement(scores: list): """ From e21b1a4d32c145d6c636499be255bc3099edc2d7 Mon Sep 17 00:00:00 2001 From: Cebolwethu Mzanywa Date: Sat, 18 Oct 2025 23:27:34 +0200 Subject: [PATCH 2/4] wrote few functions --- student_code.py | 105 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 91 insertions(+), 14 deletions(-) diff --git a/student_code.py b/student_code.py index 07a5d3c..2821219 100644 --- a/student_code.py +++ b/student_code.py @@ -102,7 +102,14 @@ def even_numbers(n: int): Returns: list: A list of even integers from 1 to n. """ - pass + even_num_list = [] + + if n > 0: + for i in range(1, n + 1): + if i%2 == 0: + even_num_list.append(i) + + return even_num_list def odd_numbers(n: int): """ @@ -114,7 +121,14 @@ def odd_numbers(n: int): Returns: list: A list of odd integers from 1 to n. """ - pass + odd_num_list = [] + + if n > 0: + for i in range(1, n + 1): + if i%3 == 0: + odd_num_list.append(i) + + return odd_num_list def sum_multiples_of_num(num: int, length: int): """ @@ -127,7 +141,19 @@ def sum_multiples_of_num(num: int, length: int): Returns: int: The sum of multiples of num from 1 to length. """ - pass + multiples_list = [] + sum = 0 + count = 1 + while len(multiples_list) < length: + + if count % num == 0: + multiples_list.append(count) + count += 1 + + for x in multiples_list: + sum += x + + return sum def skip_num(n: int, length: int): """ @@ -140,7 +166,16 @@ def skip_num(n: int, length: int): Returns: list: A list of integers from 1 to length, excluding n. """ - pass + my_list = [] + count = 0 + + while count < length: + count += 1 + if count == n: + continue + my_list.append(count) + + return my_list def break_test(n: int, length: int): """ @@ -153,7 +188,13 @@ def break_test(n: int, length: int): Returns: list: A list of integers from 1 to length, excluding n and stopping before it. """ - pass + my_list = [] + for i in range(1, length + 1): + if i == n: + break + my_list.append(i) + + return my_list def sum_numbers_until_zero(nums: list): """ @@ -165,7 +206,11 @@ def sum_numbers_until_zero(nums: list): Returns: int: The sum of integers in the list up to (but not including) the first zero. """ - pass + sum = 0 + for i in nums: + sum += i + + return sum def count_positive_numbers(nums: list): """ @@ -177,7 +222,12 @@ def count_positive_numbers(nums: list): Returns: int: The count of positive integers in the list. """ - pass + count = 0 + for i in nums: + if i > 0: + count += 1 + + return count def sum_dictionary_values(dictionary: dict): """ @@ -189,7 +239,11 @@ def sum_dictionary_values(dictionary: dict): Returns: int: The sum of all values in the dictionary. """ - pass + sum = 0 + for x, y in dictionary.items(): + sum += y + + return sum def sum_unique_elements(elements: list): """ @@ -201,7 +255,11 @@ def sum_unique_elements(elements: list): Returns: int: The sum of unique integers in the list. """ - pass + sum = 0 + for i in tuple(elements): + sum += i + + return sum def skip_divisible_by_num(n: int, length: int): """ @@ -214,7 +272,13 @@ def skip_divisible_by_num(n: int, length: int): Returns: list: A list of integers from 1 to length, excluding those divisible by n. """ - pass + my_list = [] + for i in range(1, length): + if i % n == 0: + continue + my_list.append(i) + + return my_list """Learning Outcome: Processing Data""" @@ -228,7 +292,12 @@ def square_numbers(nums: list): Returns: list: A list containing the squares of the input integers. """ - pass + my_list = [] + for i in nums: + x = i**2 + my_list.append(x) + + return my_list def transform_string(input: str, transform: str): """ @@ -256,7 +325,10 @@ def sum_and_average(nums: list[int]): Returns: tuple: A tuple containing the sum and average of the numbers. """ - pass + total = sum(nums) + average = total/len(nums) + + return (total, average) def word_frequency_count(words: list[str]): """ @@ -268,7 +340,12 @@ def word_frequency_count(words: list[str]): Returns: dict: A dictionary with words as keys and their frequencies as values. """ - pass + my_dict = {} + for word in words: + count = words.count(word) + my_dict[word] = count + + return my_dict def filter_even_numbers(nums: list[int]): """ @@ -280,7 +357,7 @@ def filter_even_numbers(nums: list[int]): Returns: list: A list containing only the even integers from the input list. """ - pass + my_list = [] """Learning Outcome: Simple Algorithms(Problem Solving)""" From 730560ba820d7df9df079f1d49d553d728e176d5 Mon Sep 17 00:00:00 2001 From: Cebolwethu Mzanywa Date: Mon, 20 Oct 2025 19:34:04 +0200 Subject: [PATCH 3/4] added few functions --- student_code.py | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/student_code.py b/student_code.py index 2821219..e2d228a 100644 --- a/student_code.py +++ b/student_code.py @@ -358,6 +358,11 @@ def filter_even_numbers(nums: list[int]): list: A list containing only the even integers from the input list. """ my_list = [] + for num in nums: + if num % 2 == 0: + my_list.append(num) + + return my_list """Learning Outcome: Simple Algorithms(Problem Solving)""" @@ -374,7 +379,18 @@ def find_median(nums: list[int]): Raises: ValueError: If the list is empty. """ - pass + if not nums: + raise ValueError("Your list is empty") + nums.sort() + n = len(nums) + if n % 2== 0: + md1 = nums[n//2 - 1] + md2 = nums[n//2] + median = (md1 + md2)/2 + return median + if n % 2 != 0: + median = nums[n//2] + return median def reverse_string(input: str): """ @@ -386,7 +402,7 @@ def reverse_string(input: str): Returns: str: The reversed string. """ - pass + return input[::-1] def largest_number(nums: list[int]): """ @@ -398,7 +414,12 @@ def largest_number(nums: list[int]): Returns: int or None: The largest number in the list, or None if the list is empty. """ - pass + max_num = 0 + for num in nums: + if max_num < num: + max_num = num + + return max_num def is_prime(n: int): """ @@ -410,8 +431,12 @@ def is_prime(n: int): Returns: bool: True if the number is prime, False otherwise. """ - pass - + for i in range(2, n): + if n % i != 0: + return True + else: + return False + def count_character_occurrences(word_sentence: str, char_count: str): """ Count the occurrences of a character in a given sentence. @@ -423,4 +448,9 @@ def count_character_occurrences(word_sentence: str, char_count: str): Returns: int: The number of occurrences of the character in the sentence. """ - pass \ No newline at end of file + count = 0 + for i in word_sentence: + if char_count == i: + count += 1 + + return count \ No newline at end of file From f48defdd20730906f449b27b7df29a745dd11ad8 Mon Sep 17 00:00:00 2001 From: cemzajhb025 Date: Tue, 21 Oct 2025 15:54:45 +0200 Subject: [PATCH 4/4] oio --- __pycache__/student_code.cpython-310.pyc | Bin 0 -> 11269 bytes tests/__pycache__/test.cpython-310.pyc | Bin 0 -> 854 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 __pycache__/student_code.cpython-310.pyc create mode 100644 tests/__pycache__/test.cpython-310.pyc diff --git a/__pycache__/student_code.cpython-310.pyc b/__pycache__/student_code.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..81aacabf357c2b8c7319bcd06b901b5a0b795c5a GIT binary patch literal 11269 zcmd5?-ESP%b)T6Xu9i!3O)f>rqAYt%s}a|crP%qftthD-*(!oIvLg#=KD!w1y(FjH zomt+Q6-{CV6jk$-JQnC%V87L`Z5{#?XkQAXe?Wl(^V&XC&j#8cFp~Vvx%bY_j&@~5 zg^^O&(cC-t^PJ!Lyf;}{X*&43{geOQ|J#n^{3jL4e+wwQfnWOfuHy*j`;Ks>yXy&0 z)c(f*z9)QH6AP&EMO~aijV~H<0pAxz6Qw#zHI$abGD@e!imb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