Ayanda#5
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR contains attempted implementations of multiple Python functions focused on learning outcomes including functions, loops, data processing, and algorithms. However, the implementations contain numerous logic errors and bugs that prevent the functions from working correctly.
Key Issues:
- Early return statements inside loops causing functions to only process first iteration
- Functions overwriting their input parameters with empty collections
- Incorrect variable references and logic errors throughout
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 19 comments.
| File | Description |
|---|---|
| student_code.py | Contains buggy implementations of educational Python functions with multiple logic errors, early returns in loops, and incorrect variable usage |
| .vscode/settings.json | Adds VS Code configuration for Python unit testing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| @@ -1,5 +1,11 @@ | |||
| """Learning Outcome: Functions""" | |||
| def sum_of_squares(n: int): | |||
| if num <= 0: | |||
There was a problem hiding this comment.
Variable name mismatch: the parameter is 'n' but the code references 'num'. This should be 'if n <= 0:'.
| if num <= 0: | |
| if n <= 0: |
| for num in range (1, n + 1): | ||
| sum += num * num | ||
| return sum |
There was a problem hiding this comment.
The return statement is inside the loop, causing the function to return after the first iteration. Move 'return sum' outside the loop to calculate the complete sum of squares.
| min_pass = 75 | ||
| grades = [] | ||
|
|
There was a problem hiding this comment.
The function parameters are immediately overwritten with hardcoded values, discarding the input arguments. Remove these lines to use the actual parameters passed to the function.
| min_pass = 75 | |
| grades = [] |
| for grade in grades: | ||
| if grade >= min_pass: | ||
| return "Pass" | ||
| else: | ||
| return "Fail" |
There was a problem hiding this comment.
The return statement inside the loop causes the function to return after checking only the first grade. This should likely accumulate results or return a list of pass/fail statuses for all grades.
| pass | ||
|
|
||
| def calculate_cumulative_performance(scores: dict): | ||
| average = sum[scores]/ len[scores] |
There was a problem hiding this comment.
Incorrect syntax: 'sum' and 'len' are functions and require parentheses, not square brackets. This should be 'sum(scores) / len(scores)'. Additionally, 'scores' is a dict, so you likely need 'scores.values()'.
| average = sum[scores]/ len[scores] | |
| average = sum(scores.values()) / len(scores.values()) |
| nums = [] | ||
| median = sum(nums) / 2 | ||
| return median |
There was a problem hiding this comment.
The 'nums' parameter is overwritten with an empty list, and median calculation is incorrect (dividing sum by 2 instead of finding the middle value). Remove line 316 and implement proper median logic by sorting the list and finding the middle element(s).
| nums = [] | |
| median = sum(nums) / 2 | |
| return median | |
| if not nums: | |
| raise ValueError("The list is empty.") | |
| nums_sorted = sorted(nums) | |
| n = len(nums_sorted) | |
| mid = n // 2 | |
| if n % 2 == 1: | |
| return float(nums_sorted[mid]) | |
| else: | |
| return (nums_sorted[mid - 1] + nums_sorted[mid]) / 2 |
|
|
||
| def reverse_string(input: str): | ||
|
|
||
| return reverse_string[::-1] |
There was a problem hiding this comment.
Variable name error: 'reverse_string' is the function name, not the input parameter. This should be 'return input[::-1]'.
| return reverse_string[::-1] | |
| return input[::-1] |
| pass | ||
|
|
||
| def largest_number(nums: list[int]): | ||
| nums = [] |
There was a problem hiding this comment.
The input parameter 'nums' is overwritten with an empty list, discarding the actual input. Remove this line to process the provided list.
| nums = [] |
| for num in range(n): | ||
| if num // num == 1 and num // 1 == num: | ||
| return True | ||
| else: | ||
| return False |
There was a problem hiding this comment.
The prime checking logic is incorrect. The condition 'num // num == 1' will cause division by zero when num=0, and the logic doesn't properly test for prime numbers. A prime number should only be divisible by 1 and itself; implement proper divisibility testing.
| for num in range(n): | |
| if num // num == 1 and num // 1 == num: | |
| 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 |
| word_sentence = "" | ||
| char_count = 0 | ||
|
|
||
| for char in word_sentence: | ||
| char_count += 1 | ||
| return char_count |
There was a problem hiding this comment.
The 'word_sentence' parameter is overwritten with an empty string, making the loop never execute. The function should count occurrences of the specific character 'char_count' (second parameter) in 'word_sentence', not total character count. Remove lines 380-381 and implement proper character counting logic.
No description provided.