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
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
160 changes: 130 additions & 30 deletions student_code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Learning Outcome: Functions"""
import math
import statistics
def sum_of_squares(n: int):
"""
Calculate the sum of the squares of all integers from 1 to n.
Expand All @@ -12,8 +13,13 @@ def sum_of_squares(n: int):
Raises:
ValueError: If n is a negative integer.
"""
pass
sumnum = []
for i in range(1, n +1):
i = pow(i,2)
sumnum.append(i)
return (sum(sumnum))

# sum_of_squares(5)
def evaluate_performance(grades: list, min_pass: int):
"""
Evaluate the performance based on a list of grades and a minimum passing grade.
Expand All @@ -25,7 +31,13 @@ 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
dict = {}
for i in grades:
if i >= min_pass:
return f"{i} Pass"
else:
return f"{i} Fail"
Comment on lines +34 to +39
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function returns immediately on the first grade instead of calculating the average of all grades as specified in the docstring. The function should compute the average of all grades and compare it to min_pass.

Suggested change
dict = {}
for i in grades:
if i >= min_pass:
return f"{i} Pass"
else:
return f"{i} Fail"
if not grades:
return "Fail"
average = sum(grades) / len(grades)
if average >= min_pass:
return "Pass"
else:
return "Fail"

Copilot uses AI. Check for mistakes.
# print(evaluate_performance([100, 70, 90, 75, 65], 75))

def calculate_cumulative_performance(scores: dict):
"""
Expand All @@ -37,7 +49,11 @@ 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
lis = []
for i in scores.values():
lis.append(i)
return sum(lis)/len(lis)
Comment on lines +52 to +55
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The return statement is inside the loop, causing the function to return after processing only the first value. Move the return statement outside the loop. Additionally, the function should return a dictionary with average and below-average subjects according to the docstring, not just a number.

Suggested change
lis = []
for i in scores.values():
lis.append(i)
return sum(lis)/len(lis)
if not scores:
return {"average": 0, "below_average_subjects": []}
average = sum(scores.values()) / len(scores)
below_average_subjects = [subject for subject, score in scores.items() if score < average]
return {"average": average, "below_average_subjects": below_average_subjects}

Copilot uses AI. Check for mistakes.
# print(calculate_cumulative_performance({"Math": 65, "English": 85, "Science": 50}))

def analyze_improvement(scores: list):
"""
Expand All @@ -50,7 +66,22 @@ def analyze_improvement(scores: list):
dict: A dictionary containing the trend of improvement ("positive", "negative", or "neutral")
and a boolean indicating whether there has been an improvement.
"""
pass
dictionary = {}
positve = False
negative = False
neutral = False
for i in scores:
if i > 0:
positve = True
return positve
elif i < 0:
negative = True
return negative
elif i == 0:
neutral = True
return neutral
Comment on lines +69 to +82
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function returns on the first score instead of analyzing the trend across all scores. The function should determine the overall trend based on all values in the list and return a dictionary with 'trend' and 'improvement' keys as specified in the docstring.

Suggested change
dictionary = {}
positve = False
negative = False
neutral = False
for i in scores:
if i > 0:
positve = True
return positve
elif i < 0:
negative = True
return negative
elif i == 0:
neutral = True
return neutral
if not scores or len(scores) == 1:
# Not enough data to determine trend
return {'trend': 'neutral', 'improvement': False}
increases = 0
decreases = 0
for prev, curr in zip(scores, scores[1:]):
if curr > prev:
increases += 1
elif curr < prev:
decreases += 1
if increases > decreases:
trend = 'positive'
improvement = True
elif decreases > increases:
trend = 'negative'
improvement = False
else:
trend = 'neutral'
improvement = False
return {'trend': trend, 'improvement': improvement}

Copilot uses AI. Check for mistakes.



def rank_students(students: list[tuple[str, int]]):
"""
Expand All @@ -75,7 +106,12 @@ def even_numbers(n: int):
Returns:
list: A list of even integers from 1 to n.
"""
pass
even = []
for i in range(1,n+1):
if i % 2 == 0:
even.append(i)
return even
# print(even_numbers(10))

def odd_numbers(n: int):
"""
Expand All @@ -87,8 +123,12 @@ def odd_numbers(n: int):
Returns:
list: A list of odd integers from 1 to n.
"""
pass

odd = []
for i in range(1,n+1):
if i % 2 != 0:
odd.append(i)
return odd
# print(odd_numbers(10))
def sum_multiples_of_num(num: int, length: int):
"""
Calculate the sum of multiples of a given number up to a specified length.
Expand All @@ -100,7 +140,11 @@ def sum_multiples_of_num(num: int, length: int):
Returns:
int: The sum of multiples of num from 1 to length.
"""
pass
lis = []
for i in range(1,length+1):
lis.append(num * i)
return sum(lis)
# print(sum_multiples_of_num(9,2))

def skip_num(n: int, length: int):
"""
Expand All @@ -113,8 +157,12 @@ def skip_num(n: int, length: int):
Returns:
list: A list of integers from 1 to length, excluding n.
"""
pass

lis = []
for i in range(1,length+1):
if i != n:
print(lis.append(i))
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The print statement wraps lis.append(i) which returns None. Remove the print wrapper and just use lis.append(i).

Suggested change
print(lis.append(i))
lis.append(i)

Copilot uses AI. Check for mistakes.
return lis
# print(skip_num(2,5))
def break_test(n: int, length: int):
"""
Generate a list of numbers from 1 to length, stopping when a specific number is encountered.
Expand All @@ -126,8 +174,12 @@ def break_test(n: int, length: int):
Returns:
list: A list of integers from 1 to length, excluding n and stopping before it.
"""
pass

lis = []
for i in range(1,length):
if i <= n:
print(lis.append(i))
Comment on lines +178 to +180
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The print statement wraps lis.append(i) which returns None. Remove the print wrapper. Additionally, the logic should break when encountering n (not <=), and it should be if i < n or use a break statement when i == n.

Suggested change
for i in range(1,length):
if i <= n:
print(lis.append(i))
for i in range(1, length):
if i == n:
break
lis.append(i)

Copilot uses AI. Check for mistakes.
return lis
# print(break_test(3,6))
def sum_numbers_until_zero(nums: list):
"""
Calculate the sum of numbers in a list until a zero is encountered.
Expand All @@ -150,7 +202,12 @@ def count_positive_numbers(nums: list):
Returns:
int: The count of positive integers in the list.
"""
pass
count = 0
for num in nums:
if num > 0:
count += 1
print(count)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function prints the count but doesn't return it. According to the docstring, the function should return an int. Change print(count) to return count.

Suggested change
print(count)
return count

Copilot uses AI. Check for mistakes.
# print(count_positive_numbers([-1,2,3,-9,-10,3]))

def sum_dictionary_values(dictionary: dict):
"""
Expand All @@ -162,7 +219,11 @@ def sum_dictionary_values(dictionary: dict):
Returns:
int: The sum of all values in the dictionary.
"""
pass
lis = []
for value in dictionary.values():
lis.append(value)
print(sum(lis))
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function prints the sum but doesn't return it. According to the docstring, the function should return an int. Change print(sum(lis)) to return sum(lis).

Suggested change
print(sum(lis))
return sum(lis)

Copilot uses AI. Check for mistakes.
# print(sum_dictionary_values( {'a': 1, 'b': 2, 'c': 3}))

def sum_unique_elements(elements: list):
"""
Expand All @@ -174,8 +235,12 @@ def sum_unique_elements(elements: list):
Returns:
int: The sum of unique integers in the list.
"""
pass

lis = []
for element in elements:
if element not in lis:
lis.append(element)
print(sum(lis))
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function prints the sum but doesn't return it. According to the docstring, the function should return an int. Change print(sum(lis)) to return sum(lis).

Suggested change
print(sum(lis))
return sum(lis)

Copilot uses AI. Check for mistakes.
# sum_unique_elements([1,1,1,2,4,5,4])
def skip_divisible_by_num(n: int, length: int):
"""
Generate a list of numbers from 1 to length, skipping those that are divisible by a specific number.
Expand All @@ -201,8 +266,11 @@ def square_numbers(nums: list):
Returns:
list: A list containing the squares of the input integers.
"""
pass

lis = []
for num in nums:
lis.append(num ** 2)
print(lis)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function prints the list but doesn't return it. According to the docstring, the function should return a list. Change print(lis) to return lis.

Suggested change
print(lis)
return lis

Copilot uses AI. Check for mistakes.
#print(square_numbers([2,3,5,7,9]))
def transform_string(input: str, transform: str):
"""
Transform a string based on the specified transformation type.
Expand All @@ -229,7 +297,8 @@ def sum_and_average(nums: list[int]):
Returns:
tuple: A tuple containing the sum and average of the numbers.
"""
pass
sum_list = sum(nums)
average = statistics.average()

Comment on lines +301 to 302
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The statistics module doesn't have an average() function. Use statistics.mean(nums) instead. Also, the function should return a tuple of (sum_list, average) as specified in the docstring.

Suggested change
average = statistics.average()
average = statistics.mean(nums)
return (sum_list, average)

Copilot uses AI. Check for mistakes.
def word_frequency_count(words: list[str]):
"""
Expand All @@ -241,7 +310,15 @@ def word_frequency_count(words: list[str]):
Returns:
dict: A dictionary with words as keys and their frequencies as values.
"""
pass
lis = {}
for word in words:
if word in lis:
lis[word] += 1
else:
lis[word] = 1
print(lis)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function prints the dictionary but doesn't return it. According to the docstring, the function should return a dict. Change print(lis) to return lis.

Suggested change
print(lis)
return lis

Copilot uses AI. Check for mistakes.

# print(word_frequency_count(["hello", "hello", "hey","sho"]))

def filter_even_numbers(nums: list[int]):
"""
Expand All @@ -253,9 +330,13 @@ def filter_even_numbers(nums: list[int]):
Returns:
list: A list containing only the even integers from the input list.
"""
pass
even = []
for num in nums:
if num % 2 == 0:
even.append(num)
print(even)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function prints the list but doesn't return it. According to the docstring, the function should return a list. Change print(even) to return even.

Suggested change
print(even)
return even

Copilot uses AI. Check for mistakes.
#print(filter_even_numbers([2,5,7,9,8,10,12,24]))

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

def find_median(nums: list[int]):
"""
Expand All @@ -270,8 +351,9 @@ def find_median(nums: list[int]):
Raises:
ValueError: If the list is empty.
"""
pass

median = statistics.median(nums)
print(median)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function prints the median but doesn't return it. According to the docstring, the function should return a float or int. Change print(median) to return median.

Suggested change
print(median)
return median

Copilot uses AI. Check for mistakes.
# print(find_median([1,2,3,5]))
def reverse_string(input: str):
"""
Reverse the given string.
Expand All @@ -282,7 +364,8 @@ def reverse_string(input: str):
Returns:
str: The reversed string.
"""
pass
return input[::-1]
# print(reverse_string("hello"))

def largest_number(nums: list[int]):
"""
Expand All @@ -294,7 +377,11 @@ def largest_number(nums: list[int]):
Returns:
int or None: The largest number in the list, or None if the list is empty.
"""
pass
largest = max(nums)
if not nums:
return None#stuck here
print(largest)
Comment on lines +380 to +383
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The empty list check happens after calling max(nums), which will raise a ValueError on an empty list. Move the if not nums check to the beginning of the function before calling max(). Also, change print(largest) to return largest.

Suggested change
largest = max(nums)
if not nums:
return None#stuck here
print(largest)
if not nums:
return None
largest = max(nums)
return largest

Copilot uses AI. Check for mistakes.
#print(largest_number([1,20,19]))

def is_prime(n: int):
"""
Expand All @@ -306,8 +393,16 @@ def is_prime(n: int):
Returns:
bool: True if the number is prime, False otherwise.
"""
pass

if n < 2:
return False
if n == 2:
return True
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The function doesn't check if n is even before starting the loop at 3 with step 2. Add a check if n % 2 == 0: return False after the n == 2 check to handle even numbers correctly.

Suggested change
return True
return True
if n % 2 == 0:
return False

Copilot uses AI. Check for mistakes.
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True

# print(is_prime(71))
def count_character_occurrences(word_sentence: str, char_count: str):
"""
Count the occurrences of a character in a given sentence.
Expand All @@ -319,4 +414,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 word in word_sentence.lower():
if word == char_count:
count += 1
return print(count)
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The expression return print(count) returns None since print() returns None. Change this to return count to return the integer count as specified in the docstring.

Suggested change
return print(count)
return count

Copilot uses AI. Check for mistakes.
# print(count_character_occurrences("My name is Ashly", "a"))