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
198 changes: 198 additions & 0 deletions Latoya's student_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
"""Learning Outcome: Functions"""
def sum_of_squares(n: int):
for i in range(1, n + 1):
sum = i ** 2
return sum
Comment on lines +3 to +5
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 only returns the square of the last number instead of the sum of all squares. Initialize sum = 0 before the loop and use sum += i ** 2 inside the loop to accumulate the total.

Suggested change
for i in range(1, n + 1):
sum = i ** 2
return sum
total = 0
for i in range(1, n + 1):
total += i ** 2
return total

Copilot uses AI. Check for mistakes.
if n < 0:
raise ValueError("n must be a postive integer")
Comment on lines +3 to +7
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 validation check is unreachable because it appears after the return statement. Move this check to the beginning of the function before any processing.

Suggested change
for i in range(1, n + 1):
sum = i ** 2
return sum
if n < 0:
raise ValueError("n must be a postive integer")
if n < 0:
raise ValueError("n must be a postive integer")
for i in range(1, n + 1):
sum = i ** 2
return sum

Copilot uses AI. Check for mistakes.
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.

Corrected spelling of 'postive' to 'positive'.

Suggested change
raise ValueError("n must be a postive integer")
raise ValueError("n must be a positive integer")

Copilot uses AI. Check for mistakes.

def evaluate_performance(grades: list, min_pass: int):
avg = sum(grades) / len(grades)
return "Pass" if avg >= min_pass else "Fail"
if not grades:
return "Fail"
Comment on lines +10 to +13
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 is unreachable because it appears after the return statement. Move this validation to the beginning of the function to prevent division by zero on line 10.

Suggested change
avg = sum(grades) / len(grades)
return "Pass" if avg >= min_pass else "Fail"
if not grades:
return "Fail"
if not grades:
return "Fail"
avg = sum(grades) / len(grades)
return "Pass" if avg >= min_pass else "Fail"

Copilot uses AI. Check for mistakes.

def calculate_cumulative_performance(scores: dict):
average = sum(scores.values()) / len(scores)
below_average = []
for subject, score in scores.items():
if score < avg:
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.

Variable avg is undefined; should be average to match the variable defined on line 16.

Suggested change
if score < avg:
if score < average:

Copilot uses AI. Check for mistakes.
below_average.append(subject)
return {"average": average, "below_average_subjects": below_average}

if not scores:
return {"average": 0, "below_average_subjects": []}
Comment on lines +16 to +24
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 dictionary check is unreachable because it appears after the return statement. Move this validation to the beginning of the function to prevent division by zero on line 16.

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

Copilot uses AI. Check for mistakes.

def analyze_improvement(scores: list):
if len(scores) < 2:
return {"trend": "neutral", "improved": False}

diff = scores[-1] - scores[0]

if diff > 0:
return {"trend": "positive", "improved": True
elif diff < 0:
return {"trend": "negative", "improved": False}
else:
return {"trend": "neutral", "improved": False}


def rank_students(students: list[tuple[str, int]]):
sorted_students = sorted(students, key=get_score, reverse=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.

Function get_score is undefined. Replace with a lambda function: key=lambda x: x[1] to extract the score from each tuple.

Suggested change
sorted_students = sorted(students, key=get_score, reverse=True)
sorted_students = sorted(students, key=lambda x: x[1], reverse=True)

Copilot uses AI. Check for mistakes.
return sorted_students

"""Learning Outcome: Basic Loops"""
def even_numbers(n: int):
for i in range(1, n + 1):
if i % 2 == 0:
return i
pass
Comment on lines +46 to +49
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 only the first even number instead of a list of all even numbers. Initialize an empty list before the loop, append even numbers to it, and return the list after the loop.

Suggested change
for i in range(1, n + 1):
if i % 2 == 0:
return i
pass
evens = []
for i in range(1, n + 1):
if i % 2 == 0:
evens.append(i)
return evens

Copilot uses AI. Check for mistakes.

def odd_numbers(n: int):
for i in range(1, n + 1):
if i % 2 != 0:
return i
Comment on lines +52 to +54
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 only the first odd number instead of a list of all odd numbers. Initialize an empty list before the loop, append odd numbers to it, and return the list after the loop.

Suggested change
for i in range(1, n + 1):
if i % 2 != 0:
return i
odds = []
for i in range(1, n + 1):
if i % 2 != 0:
odds.append(i)
return odds

Copilot uses AI. Check for mistakes.

def sum_multiples_of_num(num: int, length: int):
for i in range(1, length + 1):
sum = num * i
return sum
pass

def skip_num(n: int, length: int):
for i in range(1, length + 1):
if i != n:
return i
Comment on lines +63 to +65
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 only the first number that isn't n instead of a list of all numbers except n. Initialize an empty list before the loop, append qualifying numbers to it, and return the list after the loop.

Suggested change
for i in range(1, length + 1):
if i != n:
return i
result = []
for i in range(1, length + 1):
if i != n:
result.append(i)
return result

Copilot uses AI. Check for mistakes.
def break_test(n: int, length: int):
result = []
for i in range(1, length + 1):
if i == n:
break
result.append(i)
return result
pass

def sum_numbers_until_zero(nums: list):
total = 0
for num in nums:
if num == 0:
break
total += num
return total
pass

def count_positive_numbers(nums: list):
count = 0
for num in nums:
if num > 0:
count += 1
return count
pass

def sum_dictionary_values(dictionary: dict):
return sum(dictionary.values())
pass

def sum_unique_elements(elements: list):
return sum(set(elements))
pass

def skip_divisible_by_num(n: int, length: int):
result = []
for i in range(1, length + 1):
if i % n != 0:
result.append(i)
return result
pass

"""Learning Outcome: Processing Data"""

def square_numbers(nums: list):
for num in nums:
square = num ** 2
return square
pass
Comment on lines +111 to +114
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 only the square of the first number instead of a list of all squares. Initialize an empty list before the loop, append each square to it, and return the list after the loop.

Suggested change
for num in nums:
square = num ** 2
return square
pass
squares = []
for num in nums:
squares.append(num ** 2)
return squares

Copilot uses AI. Check for mistakes.

def transform_string(input: str, transform: str):
if transform == "capitalize":
return input.capitalize()
elif transform == "upper":
return input.upper()
elif transform == "lower":
return input.lower()
else:
raise ValueError("Unknown transformation type")
pass

def sum_and_average(nums: list[int]):
total = sum(nums)
average = total / len(nums)
return (total, average)
if not nums:
return (0, 0)
Comment on lines +128 to +132
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 is unreachable because it appears after the return statement. Move this validation to the beginning of the function to prevent division by zero on line 129.

Suggested change
total = sum(nums)
average = total / len(nums)
return (total, average)
if not nums:
return (0, 0)
if not nums:
return (0, 0)
total = sum(nums)
average = total / len(nums)
return (total, average)

Copilot uses AI. Check for mistakes.
pass

def word_frequency_count(words: list[str]):
freq = {}
for word in words:
freq[word] = freq.get(word, 0) + 1
return freq
pass

def filter_even_numbers(nums: list[int]):
for num in nums:
if num % 2 == 0:
return num
pass
Comment on lines +143 to +146
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 only the first even number instead of a list of all even numbers. Initialize an empty list before the loop, append even numbers to it, and return the list after the loop.

Suggested change
for num in nums:
if num % 2 == 0:
return num
pass
even_nums = []
for num in nums:
if num % 2 == 0:
even_nums.append(num)
return even_nums

Copilot uses AI. Check for mistakes.

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

def find_median(nums: list[int]):
"""
Find the median of a list of numbers.

Parameters:
nums (list[int]): A list of integers.

Returns:
float: The median value of the list.

Raises:
ValueError: If the list is empty.
"""
pass

def reverse_string(input: str):
reversed_text = input("Enter Text: ")
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.

Line 166 incorrectly calls the input() built-in function which prompts for user input, overwriting the function parameter. Initialize reversed_text as an empty string instead: reversed_text = ''.

Suggested change
reversed_text = input("Enter Text: ")
reversed_text = ''

Copilot uses AI. Check for mistakes.
for char in input:
reversed_text = char + reversed_text
return reversed_text

pass

def largest_number(nums: list[int]):
largest = nums[0]
for num in nums:
if num > largest:
largest = num
return largest

if not nums:
return None
pass

Comment on lines +174 to +183
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 is unreachable because it appears after the return statement. Move this validation to the beginning of the function to prevent an IndexError on line 174.

Suggested change
largest = nums[0]
for num in nums:
if num > largest:
largest = num
return largest
if not nums:
return None
pass
if not nums:
return None
largest = nums[0]
for num in nums:
if num > largest:
largest = num
return largest

Copilot uses AI. Check for mistakes.
def is_prime(n: int):
"""
Check if a number is prime.

Parameters:
n (int): The number to check.

Returns:
bool: True if the number is prime, False otherwise.
"""
pass

def count_character_occurrences(word_sentence: str, char_count: str):
return word_sentence.count(char_count)
pass
Loading