Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/student_code.cpython-310.pyc
Binary file not shown.
180 changes: 157 additions & 23 deletions student_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'postive' to 'positive'.

Suggested change
return f"Enter a postive number"
return f"Enter a positive number"

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +21
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try-except block doesn't match the documented behavior. The function should raise ValueError for negative integers, but the current implementation will never trigger the except block since range() doesn't raise ValueError. Input validation should check if n < 0 and raise ValueError explicitly.

Suggested change
try:
sum = 0
for i in range(1, n + 1):
sum += i **2
return sum
except ValueError:
return f"Enter a postive number"
if n < 0:
raise ValueError("n must be a non-negative integer")
sum = 0
for i in range(1, n + 1):
sum += i **2
return sum

Copilot uses AI. Check for mistakes.

def evaluate_performance(grades: list, min_pass: int):
"""
Expand All @@ -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"
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using f-string for a static string is unnecessary. Return the plain string "Pass" instead (note: should be capitalized "Pass" to match the docstring specification).

Suggested change
return f"pass"
return "Pass"

Copilot uses AI. Check for mistakes.
else:
return f"fail"
Comment on lines +40 to +42
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using f-string for a static string is unnecessary. Return the plain string "Fail" instead (note: should be capitalized "Fail" to match the docstring specification).

Suggested change
return f"pass"
else:
return f"fail"
return "Pass"
else:
return "Fail"

Copilot uses AI. Check for mistakes.

def calculate_cumulative_performance(scores: dict):
"""
Expand All @@ -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

Comment on lines +65 to 68
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return dictionary structure is incorrect. According to the docstring, it should return a dictionary with keys like "average_score" and "below_average", not use the numeric average_score value as a key. Expected structure: {"average_score": average_score, "below_average": list_below_average}.

Suggested change
my_dict[average_score] = list_below_average
return my_dict
return {"average_score": average_score, "below_average": list_below_average}

Copilot uses AI. Check for mistakes.
def analyze_improvement(scores: list):
"""
Expand Down Expand Up @@ -75,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):
"""
Expand All @@ -87,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:
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error: this checks for multiples of 3, not odd numbers. Should be if i % 2 != 0: to identify odd numbers.

Suggested change
if i%3 == 0:
if i % 2 != 0:

Copilot uses AI. Check for mistakes.
odd_num_list.append(i)

return odd_num_list

def sum_multiples_of_num(num: int, length: int):
"""
Expand All @@ -100,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):
"""
Expand All @@ -113,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):
"""
Expand All @@ -126,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):
"""
Expand All @@ -138,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:
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function doesn't implement the documented behavior. According to the docstring, it should sum numbers "up to (but not including) the first zero", but this implementation sums all numbers including zeros. Need to add a break condition when encountering zero: if i == 0: break.

Suggested change
for i in nums:
for i in nums:
if i == 0:
break

Copilot uses AI. Check for mistakes.
sum += i

return sum

def count_positive_numbers(nums: list):
"""
Expand All @@ -150,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):
"""
Expand All @@ -162,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):
"""
Expand All @@ -174,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):
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting to tuple doesn't remove duplicates as required by the function's purpose. Use set(elements) instead of tuple(elements) to sum only unique elements.

Suggested change
for i in tuple(elements):
for i in set(elements):

Copilot uses AI. Check for mistakes.
sum += i

return sum

def skip_divisible_by_num(n: int, length: int):
"""
Expand All @@ -187,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):
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Range is off by one. Should be range(1, length + 1) to include all integers from 1 to length as specified in the docstring.

Suggested change
for i in range(1, length):
for i in range(1, length + 1):

Copilot uses AI. Check for mistakes.
if i % n == 0:
continue
my_list.append(i)

return my_list

"""Learning Outcome: Processing Data"""

Expand All @@ -201,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):
"""
Expand Down Expand Up @@ -229,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]):
"""
Expand All @@ -241,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
Comment on lines +343 to +348
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling words.count(word) inside a loop over the same list results in O(n²) time complexity. Use a more efficient approach by incrementing counts in a single pass through the list.

Suggested change
my_dict = {}
for word in words:
count = words.count(word)
my_dict[word] = count
return my_dict
from collections import Counter
my_dict = Counter(words)
return dict(my_dict)

Copilot uses AI. Check for mistakes.

def filter_even_numbers(nums: list[int]):
"""
Expand All @@ -253,7 +357,12 @@ def filter_even_numbers(nums: list[int]):
Returns:
list: A list containing only the even integers from the input list.
"""
pass
my_list = []
for num in nums:
if num % 2 == 0:
my_list.append(num)

return my_list

"""Learning Outcome: Simple Algorithms(Problem Solving)"""

Expand All @@ -270,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):
"""
Expand All @@ -282,7 +402,7 @@ def reverse_string(input: str):
Returns:
str: The reversed string.
"""
pass
return input[::-1]

def largest_number(nums: list[int]):
"""
Expand All @@ -294,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

Comment on lines +417 to +421
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing max_num to 0 fails for lists containing only negative numbers. For an empty list, the function returns 0 instead of None as documented. Should check if list is empty first and return None, otherwise initialize max_num to the first element or use max(nums).

Suggested change
max_num = 0
for num in nums:
if max_num < num:
max_num = num
if not nums:
return None
max_num = nums[0]
for num in nums[1:]:
if max_num < num:
max_num = num

Copilot uses AI. Check for mistakes.
return max_num

def is_prime(n: int):
"""
Expand All @@ -306,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
Comment on lines +434 to +438
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prime number logic is incorrect. The function returns True on the first non-divisor, which is wrong. It should check all numbers from 2 to n-1 (or sqrt(n) for efficiency) and only return True if none divide n evenly. Also, numbers less than 2 should return False.

Suggested change
for i in range(2, n):
if n % i != 0:
return True
else:
return False
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True

Copilot uses AI. Check for mistakes.

def count_character_occurrences(word_sentence: str, char_count: str):
"""
Count the occurrences of a character in a given sentence.
Expand All @@ -319,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
count = 0
for i in word_sentence:
if char_count == i:
count += 1

return count
Binary file added tests/__pycache__/test.cpython-310.pyc
Binary file not shown.